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

Allow some env vars to override config variables, but not command line arguments #2381

Merged
merged 9 commits into from Nov 2, 2022

Conversation

aaronkollasch
Copy link
Contributor

@aaronkollasch aaronkollasch commented Oct 25, 2022

Giving #1281 a go.

This PR allows certain environment variables to take precedence over config settings, while allowing them to be overridden by their respective command line flags.

It does this by formatting those variables as a vector of command line args, and then inserting them between the config variables and command line args in App::matches(). Parsing the env variables in that way allows some env variable-specific code in App to be removed as well.

Right now, the env variables I picked are BAT_TABS, BAT_THEME, BAT_PAGER, and BAT_STYLE as I think those make the most sense to replace. It is straightforward to add more if needed. Note that BAT_PAGER takes precedence over config variables, but PAGER does not.

Also adds tests for the cache subcommand to make sure the changes don't break it (e.g. by inserting flags before cache).

Fixes #1152

src/bin/bat/app.rs Outdated Show resolved Hide resolved
@aaronkollasch aaronkollasch force-pushed the env-override-config-not-flags branch 3 times, most recently from d806d9b to 386ac65 Compare October 28, 2022 19:31
tests/integration_tests.rs Outdated Show resolved Hide resolved
CHANGELOG.md Outdated Show resolved Hide resolved
Copy link
Owner

@sharkdp sharkdp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What an excellent PR. Good description, a ChangeLog entry, useful and sensible unit tests. And a really cool idea for implementing this feature that I hadn't thought of. Thank you very much!

Added some minor remarks as inline comments.

aaronkollasch and others added 9 commits November 2, 2022 16:48
Treat the cache subcommand differently from --no-config:
For --no-config, insert args from selected environment variables
For cache, don't insert args
Co-authored-by: David Peter <sharkdp@users.noreply.github.com>
Co-authored-by: David Peter <sharkdp@users.noreply.github.com>
@aaronkollasch
Copy link
Contributor Author

aaronkollasch commented Nov 2, 2022

Thank you for reviewing @sharkdp! I'm happy with how this one came together.

Should be ready to go.

@sharkdp sharkdp merged commit 78a67ac into sharkdp:master Nov 2, 2022
@sharkdp
Copy link
Owner

sharkdp commented Nov 2, 2022

Thank you for the updates!

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.

Env var should take precedence over config
2 participants