-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Add systemwide config file support #1888
Add systemwide config file support #1888
Conversation
818e044
to
6617650
Compare
@patrickpichler Thank you very much. This looks good to me, except for one minor inline comment. Can we please add a test for this? For CI, I guess we could either create a file in |
6617650
to
1f47b80
Compare
@sharkdp I like the idea with the test, but I'm not 100% sure how to add it. |
Hm.. I didn't really think about it. Maybe that's not possible, you're right. I thought it might work to just build normally but then test with I'd be okay with a CI-only test where it would be fine to set I realize this doesn't sound too appealing, so I'm also glad to hear other ideas. |
1f47b80
to
a2e937c
Compare
If i understand the
One idea would be to do something like git is doing. They allow to override the location |
Oh 🙈. You are absolutely right.
I think I would now prefer a custom test stage in the CI script where we explicitly place a system config file in I hope there is no clash with the existing I realize that it sounds like a lot of effort for a minor piece of code. But we really want to make sure that we have a solid testing framework in order to reduce the maintenance work in the future. Having a solid test for this will ensure that this feature continues to work in the future. That said, if it turns out that maintaining the test code for this could result in major maintenance work in the future, I'm also okay with merging this without a test. |
Mhm I guess this will cause issues in the Run ignored-by-default unit tests with new syntaxes and themes step. I could change it to explicitly provide the How does this sound? |
Sounds great! |
@sharkdp I've added some tests, plus made the required changes in the last commit 👍 |
25f6f03
to
fccb57d
Compare
@sharkdp any update on this? |
tests/system_wide_config.rs
Outdated
fn bat_raw_command() -> Command { | ||
let mut cmd = Command::cargo_bin("bat").unwrap(); | ||
cmd.current_dir("tests/examples"); | ||
cmd.env_remove("BAT_CACHE_PATH"); | ||
cmd.env_remove("BAT_CONFIG_DIR"); | ||
cmd.env_remove("BAT_CONFIG_PATH"); | ||
cmd.env_remove("BAT_OPTS"); | ||
cmd.env_remove("BAT_PAGER"); | ||
cmd.env_remove("BAT_STYLE"); | ||
cmd.env_remove("BAT_TABS"); | ||
cmd.env_remove("BAT_THEME"); | ||
cmd.env_remove("COLORTERM"); | ||
cmd.env_remove("NO_COLOR"); | ||
cmd.env_remove("PAGER"); | ||
cmd | ||
} | ||
|
||
fn bat() -> assert_cmd::Command { | ||
assert_cmd::Command::from_std(bat_raw_command()) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it would be great to move this duplicated(?) code to a common test-helper module
tests/system_wide_config.rs
Outdated
assert_cmd::Command::from_std(bat_raw_command()) | ||
} | ||
|
||
// This test is ignored, as it needs a special system wide config put into place |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we please add instruction on how to enable it? currently, it sounds like it is ignored for good :-). or maybe just add a reference to the CI config.
Thank you for the updates! Could you please add an entry to the CHANGELOG? See instructions here: https://github.com/sharkdp/bat/blob/master/CONTRIBUTING.md#add-an-entry-to-the-changelog |
@sharkdp I've added the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you
Tests are currently failing |
878db6b
to
6d69225
Compare
cmd | ||
} | ||
|
||
pub fn bat_raw_command() -> Command { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this function (or the whole module) should be #[cfg(test)]
, to silence the warnings. Sorry, just saw this now.
Similar for the other functions in this file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've tried putting #[cfg(test)]
on there, but cargo test
still emits the warning when building.
Or did you mean some other warnings?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After looking at it again, I guess rust still emits a warning, as the function is only
used in unix tests. I'm not 100% sure how to fix this though, as one cannot put multiple
cfg
annotations on top. Do you maybe have an idea?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#[cfg(test)] is not enough (but does not hurt), because the mod is brought into scope by a test, but then never used. There are ways to restructure the code, but I don't think it is worth it, so let's just allow it, at least for now.
67d354f
to
1ce36e6
Compare
There is now support for a systemwide config file. The location of the system wide config file is `$(BAT_SYSTEM_CONFIG_PREFIX)/bat/config`. `$(BAT_SYSTEM_CONFIG_PREFIX)` has to be provided at compile time as an environment variable. If the environment variable is not set, a default is used. This default is `C:\ProgramData` for windows and `/etc` for every other os.
There is now a new stage in the CICD workflow present, which will build `bat` with the `BAT_SYSTEM_CONFIG_PREFIX` set to load the config file from `/tests/examples/system_config/bat/config`, plus a basic set of tests, to ensure the feature is working as expected. By default the tests are set to ignored, as they need special setup before they can be run.
@sharkdp @Enselic any update on this? The warnings also show up for other shared utility methods such as the one defined in Do you have any plan what I could do here? |
1ce36e6
to
6b660ef
Compare
Looks like I got rid of the warnings now, and this looks like a nice @sharkdp Any chance you can take a final look and then merge? I |
I did have another look and fully agree. Thank you @patrickpichler and @Enselic for the update. |
There is now support for a systemwide config file. The location of the
system wide config file is
$(BAT_SYSTEM_CONFIG_PREFIX)/bat/config
.$(BAT_SYSTEM_CONFIG_PREFIX)
has to be provided at compile time as anenvironment variable. If the environment variable is not set, a default
is used. This default is
C:\ProgramData
for windows and/etc
for every other os.fixes #668