Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate to opt-env-conf for Options and Config loading #282

Draft
wants to merge 38 commits into
base: main
Choose a base branch
from

Conversation

pbrisbin
Copy link
Member

@pbrisbin pbrisbin commented Oct 18, 2024

This completely replaces our options, env, and configuration handling with the off-the-shelf library that does the same. The big benefit is that now everything (well, as much as makes sense) that is an "option" or "config" is handled uniformly from CLI options -> ENV values -> config file(s) -> defaults.

For example, there is now an --exclude option (used to only be exclude in config) and there is now a cli.fail_on_differences config (used to be only a --fail-on-differences switch).

The new, complete --help:

Usage: restyle [--config-file FILE_PATH] --exclude GLOB[,GLOB...] --also-exclude GLOB[,GLOB...] --ignore-authors GLOB[,GLOB...] --ignore-branches GLOB[,GLOB...] --ignore-labels GLOB[,GLOB...] --restylers-version stable|dev|... [--debug] [--trace] [--color WHEN] [--[no-]dry-run] [--[no-]fail-on-differences] --host-directory DIRECTORY_PATH [--[no-]image-cleanup] [--manifest FILE_PATH] [--[no-]commit] [--[no-]clean] [--[no-]pull] [--restylers-[no-]net-none] --restylers-cpu-shares NUMBER --restylers-memory NUMBER<b|k|m|g> [--restylers-[no-]restricted] PATH [PATH]

Restyle local file

Available settings:
  Show this help text
  switch: -h|--help

  Output version information: 0.5.2.1
  switch: --version

  Path to the configuration file
  option: --config-file FILE_PATH
  env: CONFIG_FILE FILE_PATH

  Do anything at all
  config:
    enabled: # or null
      <boolean>

  Globs to exclude
  option: --exclude GLOB[,GLOB...]
  config:
    exclude: # or null
      - <string>

  Globs to exclude in addition to defaults
  option: --also-exclude GLOB[,GLOB...]
  config:
    also_exclude: # or null
      - <string>

  Template for restyling commit messages
  config:
    commit_template: # or null
      <string>

  Download remote file before restyling
  config:
    remote_files: # or null
      - # RemoteFile
        url: # required
          # URL to download
          <string>
        path: # required
          # Path to download to
          <string>

  Ignore authors that match globs
  option: --ignore-authors GLOB[,GLOB...]
  config:
    ignore.authors: # or null
      - <string>

  Ignore branches that match globs
  option: --ignore-branches GLOB[,GLOB...]
  config:
    ignore.branches: # or null
      - <string>

  Ignore labels that match globs
  option: --ignore-labels GLOB[,GLOB...]
  config:
    ignore.labels: # or null
      - <string>

  Version of Restylers manifest to use
  option: --restylers-version stable|dev|...
  env: RESTYLERS_VERSION stable|dev|...
  config:
    restylers_version: # or null
      <string>

  Restylers to run
  config:
    restylers: # or null
      - # any of
        [ # Restyler
          name: # required
            # Name
            <string>
          enabled: # optional
            # Enabled?
            <boolean>
          image: # optional
            # Image
            # Image
            <any>
          command: # optional
            # Command
            - <string>
          arguments: # optional
            # Arguments
            - <string>
          include: # optional
            # Globs to include
            - # Include
              <any>
          interpreters: # optional
            # Interpreters to look for
            - # Interpreter
              <any>
          delimiters: # optional
            # Delimeters
            # Delimiters
            start: # required
              # Start
              <string>
            end: # required
              # End
              <string>
        , <any>
        , <string>
        ]

  Enable debug logging
  switch: --debug

  Enable trace logging
  switch: --trace

  Enabled color WHEN
  option: --color WHEN

  Skip pulling and running Restylers
  switch: --[no-]dry-run
  env: DRY_RUN BOOL
  config:
    cli.dry_run: # or null
      <boolean>

  Exit non-zero if differences were found
  switch: --[no-]fail-on-differences
  env: FAIL_ON_DIFFERENCES BOOL
  config:
    cli.fail_on_differences: # or null
      <boolean>

  Working directory on host, if dockerized
  option: --host-directory DIRECTORY_PATH
  env: HOST_DIRECTORY DIRECTORY_PATH
  config:
    cli.host_directory: # or null
      <string>

  Remove pulled restyler images after restyling
  switch: --[no-]image-cleanup
  env: IMAGE_CLEANUP BOOL
  config:
    cli.image_cleanup: # or null
      <boolean>

  Restylers manifest to use
  option: --manifest FILE_PATH
  env: MANIFEST FILE_PATH
  config:
    cli.manifest: # or null
      <string>

  Make commits for restyle changes
  switch: --[no-]commit
  env: COMMIT BOOL
  config:
    cli.commit: # or null
      <boolean>

  Run git-clean after restyling
  switch: --[no-]clean
  env: CLEAN BOOL
  config:
    cli.clean: # or null
      <boolean>

  docker-pull images before docker-run
  switch: --[no-]pull
  env: PULL BOOL
  config:
    cli.pull: # or null
      <boolean>

  Run restylers with --net=none
  switch: --restylers-[no-]net-none
  env: RESTYLERS_NET_NONE BOOL
  config:
    cli.restylers.net_none: # or null
      <boolean>

  Run restylers with --cpu-shares
  option: --restylers-cpu-shares NUMBER
  env: RESTYLERS_CPU_SHARES NUMBER
  config:
    cli.restylers.cpu_shares: # or null
      <integer>0 or more

  Run restylers with --memory
  option: --restylers-memory NUMBER<b|k|m|g>
  env: RESTYLERS_MEMORY NUMBER<b|k|m|g>
  config:
    cli.restylers.memory: # or null
      # Bytes
      number: # required
        # a number
        <integer>0 or more
      suffix: # optional
        # a suffix
        # one of
        [ b
        , k
        , m
        , g
        ]

  Restrict restylers resources
  switch: --restylers-[no-]restricted
  env: RESTYLERS_RESTRICTED BOOL
  config:
    cli.restylers.restricted: # or null
      <boolean>

  Path to restyle
  argument: PATH

  Path to restyle
  argument: PATH

Along the way, we dropped about 1,000 lines of our code doing a poor job of some of this.

See above for all the new options, below is a list of only backwards incompatible change:

Configuration changes:

  • Unknown keys are no longer an error, to allow us compatibility to evolve
  • Unknown restylers no longer report "did you mean?", for the sake of simplicity
  • Config file errors aren't displayed quite as nicely, sorry

ENV changes:

  • UNRESTRICTED=x|<empty> is now RESTYLERS_RESTRICTED=true|false
  • Other restriction options, RESTYLER_X are now RESTYLERS_X
  • Any NO_X=x|<empty> is now X=true|false
  • TERM, NO_COLOR, LOG_* still work, but are not documented

CLI changes:

  • None

Stop validating for extra keys. This is a small hit to ergonomics in
error cases, so we can continue to simplify things in general through
off-the-shelf libraries like `opt-env-conf`.
Things that are *primarily* on `Config` are now under `Config.`. Just
like things that were *primarily* on `Options` were under `Options.`.
Obviously most things are both options and config. And both top-levels
re-export the sub-modules.

Re-export the `Config.Parse` module through `Config`. That way, when we
fully replace it there's no need to change any `import`s.

Together, this makes most code look correct already, even if we're still
working through the `Config -> Config'` conversion.
@pbrisbin pbrisbin changed the title pb/option values Migrate to opt-env-conf for Options and Config loading Oct 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants