diff --git a/cli/core/src/output.rs b/cli/core/src/output.rs index 6d1f290da..91ac2b6dc 100644 --- a/cli/core/src/output.rs +++ b/cli/core/src/output.rs @@ -154,17 +154,21 @@ impl OutputProcessor { Some(OutputFormat::Wide) => OutputFor::Human, _ => OutputFor::Machine, }; - let mut hints: Vec = args.config().hints.clone(); - - if let (Some(resource_key), Some(action)) = (&resource_key, &action) { - args.config() - .command_hints - .get(resource_key.as_ref()) - .and_then(|cmd_hints| { - cmd_hints.get(action.as_ref()).map(|val| { - hints.extend(val.clone()); - }) - }); + let mut hints: Vec = Vec::new(); + + if args.config().enable_hints { + hints.extend(args.config().hints.clone()); + + if let (Some(resource_key), Some(action)) = (&resource_key, &action) { + args.config() + .command_hints + .get(resource_key.as_ref()) + .and_then(|cmd_hints| { + cmd_hints.get(action.as_ref()).map(|val| { + hints.extend(val.clone()); + }) + }); + } } Self { @@ -914,4 +918,50 @@ mod tests { op.hints ); } + + #[test] + fn test_output_processor_from_args_hints_disabled() { + let mut config_file = Builder::new().suffix(".yaml").tempfile().unwrap(); + + const CONFIG_DATA: &str = r#" + command_hints: + res: + cmd: + - cmd_hint1 + hints: + - hint1 + enable_hints: false + "#; + + write!(config_file, "{CONFIG_DATA}").unwrap(); + + #[derive(Parser)] + struct Cli { + #[command(flatten)] + global_opts: GlobalOpts, + #[arg(long("cli-config"), value_parser = parse_config, default_value_t = Config::new().unwrap())] + config: Config, + } + + impl CliArgs for Cli { + fn global_opts(&self) -> &GlobalOpts { + &self.global_opts + } + + fn config(&self) -> &Config { + &self.config + } + } + + let op = OutputProcessor::from_args( + &Cli::parse_from([ + "osc", + "--cli-config", + &config_file.path().as_os_str().to_string_lossy(), + ]), + Some("res"), + Some("cmd"), + ); + assert_eq!(Some(Vec::::new()), op.hints); + } } diff --git a/openstack_cli/src/cli.rs b/openstack_cli/src/cli.rs index e949a7d06..f1f9a0f23 100644 --- a/openstack_cli/src/cli.rs +++ b/openstack_cli/src/cli.rs @@ -16,7 +16,7 @@ use clap::Parser; use openstack_cli_core::cli::{ CliArgs, CompletionCommand, ConnectionRequirements, ConnectionRequirementsProvider, GlobalOpts, - parse_config, styles, + styles, }; use openstack_cli_core::config::Config; use openstack_cli_core::error::OpenStackCliError; @@ -95,9 +95,8 @@ pub struct Cli { /// CLI configuration /// - /// This does not accept parameters at the moment and will always get config from default - /// location. - #[arg(hide = true, long("cli-config"), value_parser = parse_config, default_value_t = Config::new().unwrap_or_default())] + /// This does not accept parameters and always gets config from the default location. + #[arg(skip = Config::new().unwrap_or_default())] pub config: Config, }