mirror of
https://github.com/tinyhumansai/openhuman.git
synced 2026-07-28 13:32:23 +00:00
fix: report missing generic CLI parameter values (#2016)
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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 =
|
||||
|
||||
Reference in New Issue
Block a user