diff --git a/proxmox/src/api/cli/command.rs b/proxmox/src/api/cli/command.rs index d40713e9..4c01c371 100644 --- a/proxmox/src/api/cli/command.rs +++ b/proxmox/src/api/cli/command.rs @@ -30,7 +30,9 @@ fn parse_arguments( ) -> Result { let (params, remaining) = - match getopts::parse_arguments(&args, cli_cmd.arg_param, &cli_cmd.info.parameters) { + match getopts::parse_arguments( + &args, cli_cmd.arg_param, &cli_cmd.fixed_param, &cli_cmd.info.parameters + ) { Ok((p, r)) => (p, r), Err(err) => { let err_msg = err.to_string(); diff --git a/proxmox/src/api/cli/getopts.rs b/proxmox/src/api/cli/getopts.rs index dfccaa00..6fd48e85 100644 --- a/proxmox/src/api/cli/getopts.rs +++ b/proxmox/src/api/cli/getopts.rs @@ -1,3 +1,5 @@ +use std::collections::HashMap; + use anyhow::*; use serde_json::Value; @@ -146,6 +148,7 @@ pub(crate) fn parse_argument_list>( pub fn parse_arguments>( args: &[T], arg_param: &[&str], + fixed_param: &HashMap<&'static str, String>, schema: &ObjectSchema, ) -> Result<(Value, Vec), ParameterError> { let mut errors = ParameterError::new(); @@ -195,6 +198,10 @@ pub fn parse_arguments>( return Err(errors); } + for (name, value) in fixed_param.iter() { + data.push((name.to_string(), value.to_string())); + } + let options = parse_parameter_strings(&data, schema, true)?; Ok((options, remaining)) @@ -222,7 +229,7 @@ fn test_boolean_arg() { variants.push((vec!["--enable", "false"], false)); for (args, expect) in variants { - let res = parse_arguments(&args, &vec![], &PARAMETERS); + let res = parse_arguments(&args, &vec![], &HashMap::new(), &PARAMETERS); assert!(res.is_ok()); if let Ok((options, remaining)) = res { assert!(options["enable"] == expect); @@ -242,7 +249,7 @@ fn test_argument_paramenter() { ); let args = vec!["-enable", "local"]; - let res = parse_arguments(&args, &vec!["storage"], &PARAMETERS); + let res = parse_arguments(&args, &vec!["storage"], &HashMap::new(), &PARAMETERS); assert!(res.is_ok()); if let Ok((options, remaining)) = res { assert!(options["enable"] == true);