1
0
mirror of https://github.com/sharkdp/bat synced 2026-08-10 20:01:45 +00:00

Allow env vars to override config but not args

This commit is contained in:
Aaron Kollasch
2022-10-25 19:30:11 -04:00
parent 5652038f01
commit 36ccc6a31e
4 changed files with 74 additions and 18 deletions
+14 -1
View File
@@ -117,7 +117,7 @@ pub fn get_args_from_config_file() -> Result<Vec<OsString>, shell_words::ParseEr
get_args_from_str(&config)
}
pub fn get_args_from_env_var() -> Option<Result<Vec<OsString>, shell_words::ParseError>> {
pub fn get_args_from_env_opts_var() -> Option<Result<Vec<OsString>, shell_words::ParseError>> {
env::var("BAT_OPTS").ok().map(|s| get_args_from_str(&s))
}
@@ -137,6 +137,19 @@ fn get_args_from_str(content: &str) -> Result<Vec<OsString>, shell_words::ParseE
.collect())
}
pub fn get_args_from_env_vars() -> Vec<OsString> {
[
("--tabs", "BAT_TABS"),
("--theme", "BAT_THEME"),
("--pager", "BAT_PAGER"),
("--style", "BAT_STYLE"),
]
.iter()
.filter_map(|(flag, key)| env::var(key).ok().map(|var| [flag.into(), var.into()]))
.flatten()
.collect()
}
#[test]
fn empty() {
let args = get_args_from_str("").unwrap();