Treat partially-matched arguments as an error
This commit is contained in:
@@ -14,8 +14,12 @@ where
|
|||||||
if let Some(arg) = input.get(0) {
|
if let Some(arg) = input.get(0) {
|
||||||
return match f(arg) {
|
return match f(arg) {
|
||||||
Ok(("", rv)) => Ok((&input[1..], rv)),
|
Ok(("", rv)) => Ok((&input[1..], rv)),
|
||||||
// single-arg parsers must consume the entire arg
|
// single-arg parsers must consume the entire arg, so consider unconsumed
|
||||||
Ok((unconsumed, _)) => panic!("unconsumed argument input {}", unconsumed),
|
// output to be an error.
|
||||||
|
Ok((_, _)) => Err(Err::Error(Error {
|
||||||
|
input,
|
||||||
|
code: ErrorKind::Eof,
|
||||||
|
})),
|
||||||
// single-arg parsers are all complete parsers
|
// single-arg parsers are all complete parsers
|
||||||
Err(Err::Incomplete(_)) => unreachable!(),
|
Err(Err::Incomplete(_)) => unreachable!(),
|
||||||
// for error and failure, rewrite to an error at this position in the arugment list
|
// 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());
|
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());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user