diff --git a/proxmox/src/api/cli/command.rs b/proxmox/src/api/cli/command.rs index fa447bac..b91aac77 100644 --- a/proxmox/src/api/cli/command.rs +++ b/proxmox/src/api/cli/command.rs @@ -356,7 +356,7 @@ fn prepare_cli_command(def: &CommandLineInterface) -> (String, Vec) { if args[0] == "printdoc" { let usage = match def { CommandLineInterface::Simple(cli_cmd) => { - generate_usage_str(&prefix, &cli_cmd, DocumentationFormat::ReST, "") + generate_usage_str(&prefix, &cli_cmd, DocumentationFormat::ReST, "", &[]) } CommandLineInterface::Nested(map) => { generate_nested_usage(&prefix, &map, DocumentationFormat::ReST) diff --git a/proxmox/src/api/cli/format.rs b/proxmox/src/api/cli/format.rs index f780b1a5..7428867d 100644 --- a/proxmox/src/api/cli/format.rs +++ b/proxmox/src/api/cli/format.rs @@ -60,12 +60,17 @@ pub fn generate_usage_str( cli_cmd: &CliCommand, format: DocumentationFormat, indent: &str, + skip_options: &'static [&'static str], ) -> String { let arg_param = cli_cmd.arg_param; let fixed_param = &cli_cmd.fixed_param; let schema = cli_cmd.info.parameters; let mut done_hash = HashSet::<&str>::new(); + for option in skip_options { + done_hash.insert(option); + } + let mut args = String::new(); for positional_arg in arg_param { @@ -178,7 +183,7 @@ pub fn generate_usage_str( /// Print command usage for simple commands to ``stderr``. pub fn print_simple_usage_error(prefix: &str, cli_cmd: &CliCommand, err_msg: &str) { - let usage = generate_usage_str(prefix, cli_cmd, DocumentationFormat::Long, ""); + let usage = generate_usage_str(prefix, cli_cmd, DocumentationFormat::Long, "", &[]); eprint!("Error: {}\nUsage: {}", err_msg, usage); } @@ -197,6 +202,8 @@ pub fn generate_nested_usage( let mut cmds: Vec<&String> = def.commands.keys().collect(); cmds.sort(); + let skip_options = def.usage_skip_options; + let mut usage = String::new(); for cmd in cmds { @@ -211,7 +218,7 @@ pub fn generate_nested_usage( if !usage.is_empty() && format == DocumentationFormat::ReST { usage.push_str("----\n\n"); } - usage.push_str(&generate_usage_str(&new_prefix, cli_cmd, format, "")); + usage.push_str(&generate_usage_str(&new_prefix, cli_cmd, format, "", skip_options)); } CommandLineInterface::Nested(map) => { usage.push_str(&generate_nested_usage(&new_prefix, map, format)); @@ -268,7 +275,7 @@ pub fn print_help( CommandLineInterface::Simple(cli_cmd) => { println!( "Usage: {}", - generate_usage_str(&prefix, cli_cmd, format, "") + generate_usage_str(&prefix, cli_cmd, format, "", &[]) ); } } diff --git a/proxmox/src/api/cli/mod.rs b/proxmox/src/api/cli/mod.rs index 44912622..d0c21031 100644 --- a/proxmox/src/api/cli/mod.rs +++ b/proxmox/src/api/cli/mod.rs @@ -102,6 +102,8 @@ pub struct CliCommandMap { /// command definitions. pub commands: HashMap, pub aliases: Vec<(Vec<&'static str>, Vec<&'static str>)>, + /// List of options to suppress in generate_usage + pub usage_skip_options: &'static [&'static str], } impl CliCommandMap { @@ -121,6 +123,13 @@ impl CliCommandMap { self } + pub fn usage_skip_options(mut self, list: &'static [&'static str]) -> Self { + self.usage_skip_options = list; + self + } + + + /// Insert the help command. pub fn insert_help(mut self) -> Self { self.commands