From 4bcea01e9daf87bca4dde30d4ca18c1c1b966275 Mon Sep 17 00:00:00 2001 From: Aaron Kollasch Date: Tue, 25 Oct 2022 23:30:05 -0400 Subject: [PATCH] Deduplicate lines in matches function --- src/bin/bat/app.rs | 37 ++++++++++++------------------------- 1 file changed, 12 insertions(+), 25 deletions(-) diff --git a/src/bin/bat/app.rs b/src/bin/bat/app.rs index 803a4c0d..8487010f 100644 --- a/src/bin/bat/app.rs +++ b/src/bin/bat/app.rs @@ -49,45 +49,32 @@ impl App { } fn matches(interactive_output: bool) -> Result { - 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)) }