Deduplicate lines in matches function

This commit is contained in:
Aaron Kollasch 2022-10-25 23:30:05 -04:00
parent 76aad7c74f
commit 4bcea01e9d
No known key found for this signature in database
GPG Key ID: F813CAE853E39883

View File

@ -49,45 +49,32 @@ impl App {
}
fn matches(interactive_output: bool) -> Result<ArgMatches> {
let args = if wild::args_os().nth(1) == Some("cache".into())
let mut args = if wild::args_os().nth(1) == Some("cache".into())
|| wild::args_os().any(|arg| arg == "--no-config")
{
// Skip the arguments in bats config file
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
get_args_from_env_vars()
} else {
let mut cli_args = wild::args_os();
// Read arguments from bats config file
let mut args = get_args_from_env_opts_var()
.unwrap_or_else(get_args_from_config_file)
.map_err(|_| "Could not parse configuration file")?;
// Put the zero-th CLI argument (program name) first
args.insert(0, cli_args.next().unwrap());
// env vars supersede config vars
get_args_from_env_vars()
.into_iter()
.for_each(|a| args.push(a));
// .. and the rest at the end
cli_args.for_each(|a| args.push(a));
// Selected env vars supersede config vars
args.extend(get_args_from_env_vars());
args
};
let mut cli_args = wild::args_os();
// 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));
Ok(clap_app::build_app(interactive_output).get_matches_from(args))
}