mirror of
https://github.com/sharkdp/bat.git
synced 2025-01-18 20:11:03 +00:00
Deduplicate lines in matches function
This commit is contained in:
parent
76aad7c74f
commit
4bcea01e9d
@ -49,45 +49,32 @@ impl App {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn matches(interactive_output: bool) -> Result<ArgMatches> {
|
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")
|
|| wild::args_os().any(|arg| arg == "--no-config")
|
||||||
{
|
{
|
||||||
// Skip the arguments in bats config file
|
// Skip the arguments in bats config file
|
||||||
|
|
||||||
let mut cli_args = wild::args_os();
|
get_args_from_env_vars()
|
||||||
|
|
||||||
// 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 {
|
} else {
|
||||||
let mut cli_args = wild::args_os();
|
|
||||||
|
|
||||||
// Read arguments from bats config file
|
// Read arguments from bats config file
|
||||||
let mut args = get_args_from_env_opts_var()
|
let mut args = get_args_from_env_opts_var()
|
||||||
.unwrap_or_else(get_args_from_config_file)
|
.unwrap_or_else(get_args_from_config_file)
|
||||||
.map_err(|_| "Could not parse configuration file")?;
|
.map_err(|_| "Could not parse configuration file")?;
|
||||||
|
|
||||||
// Put the zero-th CLI argument (program name) first
|
// Selected env vars supersede config vars
|
||||||
args.insert(0, cli_args.next().unwrap());
|
args.extend(get_args_from_env_vars());
|
||||||
|
|
||||||
// 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));
|
|
||||||
|
|
||||||
args
|
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))
|
Ok(clap_app::build_app(interactive_output).get_matches_from(args))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user