mirror of
https://github.com/sharkdp/bat.git
synced 2025-09-02 11:22:30 +01:00
Fix cache subcommand and add tests
Treat the cache subcommand differently from --no-config: For --no-config, insert args from selected environment variables For cache, don't insert args
This commit is contained in:
@@ -49,13 +49,26 @@ impl App {
|
||||
}
|
||||
|
||||
fn matches(interactive_output: bool) -> Result<ArgMatches> {
|
||||
let mut args = if wild::args_os().nth(1) == Some("cache".into())
|
||||
|| wild::args_os().any(|arg| arg == "--no-config")
|
||||
{
|
||||
let args = if wild::args_os().nth(1) == Some("cache".into()) {
|
||||
// Skip the config file and env vars
|
||||
|
||||
wild::args_os().collect::<Vec<_>>()
|
||||
} else if wild::args_os().any(|arg| arg == "--no-config") {
|
||||
// Skip the arguments in bats config file
|
||||
|
||||
get_args_from_env_vars()
|
||||
let mut cli_args = wild::args_os();
|
||||
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();
|
||||
|
||||
// Read arguments from bats config file
|
||||
let mut args = get_args_from_env_opts_var()
|
||||
.unwrap_or_else(get_args_from_config_file)
|
||||
@@ -64,17 +77,15 @@ impl App {
|
||||
// Selected env vars supersede config vars
|
||||
args.extend(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
|
||||
};
|
||||
|
||||
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))
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user