mirror of
https://github.com/sharkdp/bat.git
synced 2025-09-02 03:12:25 +01:00
Improve correctness and add more tests
This commit is contained in:
@@ -54,7 +54,18 @@ impl App {
|
||||
{
|
||||
// Skip the arguments in bats config file
|
||||
|
||||
wild::args_os().collect::<Vec<_>>()
|
||||
let mut cli_args = wild::args_os();
|
||||
|
||||
// Load selected env vars
|
||||
let mut args = get_args_from_env_vars();
|
||||
|
||||
// Put the zero-th CLI argument (program name) first
|
||||
args.insert(0, cli_args.next().unwrap());
|
||||
|
||||
// .. and the rest at the end
|
||||
cli_args.for_each(|a| args.push(a));
|
||||
|
||||
args
|
||||
} else {
|
||||
let mut cli_args = wild::args_os();
|
||||
|
||||
@@ -68,11 +79,11 @@ impl App {
|
||||
|
||||
// env vars supersede config vars
|
||||
get_args_from_env_vars()
|
||||
.iter()
|
||||
.for_each(|a| args.push(a.into()));
|
||||
.into_iter()
|
||||
.for_each(|a| args.push(a));
|
||||
|
||||
// .. and the rest at the end
|
||||
cli_args.for_each(|a| args.push(a.into()));
|
||||
cli_args.for_each(|a| args.push(a));
|
||||
|
||||
args
|
||||
};
|
||||
|
@@ -145,8 +145,9 @@ pub fn get_args_from_env_vars() -> Vec<OsString> {
|
||||
("--style", "BAT_STYLE"),
|
||||
]
|
||||
.iter()
|
||||
.filter_map(|(flag, key)| env::var(key).ok().map(|var| [flag.into(), var.into()]))
|
||||
.filter_map(|(flag, key)| env::var(key).ok().map(|var| [flag.to_string(), var]))
|
||||
.flatten()
|
||||
.map(|a| a.into())
|
||||
.collect()
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user