diff --git a/cli/src/argparse/args/arg_matching.rs b/cli/src/argparse/args/arg_matching.rs index f52aa4254..f9582bbbb 100644 --- a/cli/src/argparse/args/arg_matching.rs +++ b/cli/src/argparse/args/arg_matching.rs @@ -14,8 +14,12 @@ where if let Some(arg) = input.get(0) { return match f(arg) { Ok(("", rv)) => Ok((&input[1..], rv)), - // single-arg parsers must consume the entire arg - Ok((unconsumed, _)) => panic!("unconsumed argument input {}", unconsumed), + // single-arg parsers must consume the entire arg, so consider unconsumed + // output to be an error. + Ok((_, _)) => Err(Err::Error(Error { + input, + code: ErrorKind::Eof, + })), // single-arg parsers are all complete parsers Err(Err::Incomplete(_)) => unreachable!(), // for error and failure, rewrite to an error at this position in the arugment list @@ -48,4 +52,9 @@ mod test { ); assert!(arg_matching(plus_tag)(argv!["foo", "bar"]).is_err()); } + + #[test] + fn test_partial_arg_matching() { + assert!(arg_matching(wait_colon)(argv!["wait:UNRECOGNIZED"]).is_err()); + } }