fix: report missing generic CLI parameter values (#2016)

This commit is contained in:
paulpanwang
2026-05-17 15:23:16 -07:00
committed by GitHub
parent 447105144e
commit d241e8c69e
2 changed files with 37 additions and 0 deletions
+6
View File
@@ -447,6 +447,12 @@ fn parse_function_params(
let raw_value = args
.get(i + 1)
.ok_or_else(|| format!("missing value for --{key}"))?;
if raw_value.starts_with("--") {
let next_key = raw_value.trim_start_matches("--").replace('-', "_");
if schema.inputs.iter().any(|input| input.name == next_key) {
return Err(format!("missing value for --{key}"));
}
}
let value = parse_input_value(&spec.ty, raw_value)?;
out.insert(key, value);
i += 2;
+31
View File
@@ -52,6 +52,37 @@ fn parse_function_params_rejects_unknown_param() {
assert!(err.contains("unknown param"));
}
#[test]
fn parse_function_params_rejects_flag_like_missing_value() {
let schema = ControllerSchema {
namespace: "test",
function: "configure",
description: "test schema",
inputs: vec![
FieldSchema {
name: "enabled",
ty: TypeSchema::Bool,
required: true,
comment: "whether the feature is enabled",
},
FieldSchema {
name: "name",
ty: TypeSchema::String,
required: true,
comment: "feature name",
},
],
outputs: vec![],
};
let args = vec![
"--enabled".to_string(),
"--name".to_string(),
"demo".to_string(),
];
let err = parse_function_params(&schema, &args).expect_err("missing value should fail");
assert_eq!(err, "missing value for --enabled");
}
#[test]
fn parse_input_value_rejects_invalid_bool() {
let err =