Improve correctness and add more tests

This commit is contained in:
Aaron Kollasch committed 2022-11-02 16:48:50 -04:00
1 parent 36ccc6a31e
commit 76aad7c74f
4 files changed
+134 -6

No files matched your search

+15 -4
View File
@@ -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
};
+2 -1
View File
@@ -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()
}