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

Rewrite option, env, and config handling #282

Merged
merged 4 commits into from
Oct 22, 2024
Merged

Rewrite option, env, and config handling #282

merged 4 commits into from
Oct 22, 2024

Conversation

pbrisbin
Copy link
Member

@pbrisbin pbrisbin commented Oct 18, 2024

This completely replaces our options, environment, and configuration
handling with the off-the-shelf library opt-env-conf.

All settings are now normalized and parsed through the three sources, we
have a much richer help and man-page output, and we dropped a massive
amount of code.

It's hard to say what users were relying on, so we aimed to be somewhat
compatible, but not completely. Options and configuration are backwards
completely compatible because we know users rely on the latter and
actions/run uses the former. We gave ourselves more liberties with
environment variables, in the interest of normalization and simplicity.

Here is a possibly-not-exhaustive summary of changes:

  • Options (backwards-compatible)
    • Added --config-file
    • Added --{also,}exclude
    • Added --ignore-{authors,branches,labels}
    • Added --restylers-version
    • Added --host-directory
    • Added --restyler-{restricted,net-none,cpu-shares,memory}
    • Every switch has both --x and --no-x.
  • Environment (backwards-compatible)
    • Added CONFIG_FILE
    • Added FAIL_ON_DIFFERENCES
    • Added {ALSO_,}EXCLUDE
    • Added IGNORE_{AUTHORS,BRANCHES,LABELS}
    • Added RESTYLERS_VERSION
  • Environment (not backwards-compatible)
    • Changed NO_IMAGE_CLEANUP to IMAGE_CLEANUP=False
    • Changed NO_PULL to PULL=False
    • Changed NO_COMMIT to COMMIT=False
    • Changed NO_CLEAN to CLEAN=False
    • Changed UNRESTRICTED to RESTYLER_RESTRICTED=False
  • Config (backwards-compatible)
    • Added logging.*
    • Added dry_run
    • Added fail_on_differences
    • Added restylers_manifest
    • Added docker.*
    • Added git.*
    • Added ignore.* (ignore_* is still supported)

For complete details, see the complete reference and the updated config/defaults.yaml

@pbrisbin pbrisbin changed the title pb/option values Migrate to opt-env-conf for Options and Config loading Oct 18, 2024
@pbrisbin pbrisbin marked this pull request as ready for review October 21, 2024 15:56
This completely replaces our options, environment, and configuration
handling with the off-the-shelf library `opt-env-conf`.

All settings are now normalized and parsed through the three sources, we
have a much richer help and man-page output, and we dropped a massive
amount of code.

It's hard to say what users were relying on, so we aimed to be somewhat
compatible, but not completely. Options and configuration are backwards
completely compatible because we know users rely on the latter and
`actions/run` uses the former. We gave ourselves more liberties with
environment variables, in the interest of normalization and simplicity.

Here is a possibly-not-exhaustive summary of changes:

* Options (backwards-compatible)
  * Added `--config-file`
  * Added `--{also,}exclude`
  * Added `--ignore-{authors,branches,labels}`
  * Added `--restylers-version`
  * Added `--host-directory`
  * Added `--restyler-{restricted,net-none,cpu-shares,memory}`
  * Every switch has both `--x` and `--no-x`.
* Environment (backwards-compatible)
  * Added `CONFIG_FILE`
  * Added `FAIL_ON_DIFFERENCES`
  * Added `{ALSO_,}EXCLUDE`
  * Added `IGNORE_{AUTHORS,BRANCHES,LABELS}`
  * Added `RESTYLERS_VERSION`
* Environment (**not** backwards-compatible)
  * Changed `NO_IMAGE_CLEANUP` to `IMAGE_CLEANUP=False`
  * Changed `NO_PULL` to `PULL=False`
  * Changed `NO_COMMIT` to `COMMIT=False`
  * Changed `NO_CLEAN` to `CLEAN=False`
  * Changed `UNRESTRICTED` to `RESTYLER_RESTRICTED=False`
* Config (backwards-compatible)
  * Added `logging.*`
  * Added `dry_run`
  * Added `fail_on_differences`
  * Added `restylers_manifest`
  * Added `docker.*`
  * Added `git.*`
  * Added `ignore.*` (`ignore_*` is still supported)
@pbrisbin pbrisbin changed the title Migrate to opt-env-conf for Options and Config loading Rewrite option, env, and config handling Oct 22, 2024
Because `LOG_*` variables are parsed outside and before we parse our
`opt-env-conf` settings, they are always overridden by the fact that we
use the config file to specify our defaults.

If we also parse those variables ourselves, we can ensure they are
respected on top of our defaults if given.

This works perfectly with `LOG_COLOR` since we parse the same structure
and can just read it at its name, but `LOG_LEVEL` has a caveat: it will
be respected when set, no matter what. That's because we are parsing
boolean switches so we can't fold that into parsing the levels value at
the same time and we must do one or the other via `(<|>)`.

In other words,

```console
LOG_COLOR=always restyle --color=never
```

Works as you expect, but

```console
LOG_LEVEL=debug restyle --trace
```

Does not.

I think this is acceptable.
@pbrisbin pbrisbin enabled auto-merge (rebase) October 22, 2024 17:57
@pbrisbin pbrisbin merged commit 837d83d into main Oct 22, 2024
7 checks passed
@pbrisbin pbrisbin deleted the pb/option-values branch October 22, 2024 17:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant