pub fn validate_command(
result: &ProbeResult,
command: &str,
args: &[String],
) -> ValidationResultExpand description
Validate a command invocation against a ProbeResult.
This checks:
- Required arguments are provided
- Required options are provided
- Options are valid (known to the command)
- Arguments match expected types
- Subcommands are valid
ยงExamples
use help_probe::{validation::validate_command, model::{ProbeResult, OptionSpec, OptionType}};
let result = ProbeResult {
command: "mytool".to_string(),
args: vec![],
exit_code: Some(0),
timed_out: false,
help_flag_detected: true,
usage_blocks: vec![],
options: vec![OptionSpec {
short_flags: vec!["-v".to_string()],
long_flags: vec!["--verbose".to_string()],
description: Some("Verbose output".to_string()),
option_type: OptionType::Boolean,
required: false,
default_value: None,
takes_argument: false,
argument_name: None,
choices: vec![],
}],
subcommands: vec![],
arguments: vec![],
examples: vec![],
environment_variables: vec![],
validation_rules: vec![],
raw_stdout: String::new(),
raw_stderr: String::new(),
};
// Valid command
let validation = validate_command(&result, "mytool", &["--verbose".to_string()]);
assert!(validation.is_valid);
// Invalid option
let validation = validate_command(&result, "mytool", &["--unknown".to_string()]);
assert!(!validation.is_valid);
assert!(validation.errors.iter().any(|e| matches!(e.error_type, help_probe::validation::ValidationErrorType::UnknownOption)));