mirror of
https://github.com/clap-rs/clap
synced 2025-03-04 23:37:32 +00:00
fix: fixed confusing error message, also added test for it
This commit is contained in:
parent
af6b58f97d
commit
fc7a31a745
3 changed files with 18 additions and 2 deletions
|
@ -280,7 +280,7 @@ impl<'n, 'l, 'h, 'g, 'p, 'r> Arg<'n, 'l, 'h, 'g, 'p, 'r> {
|
|||
}
|
||||
|
||||
Arg {
|
||||
name: name.unwrap(),
|
||||
name: name.unwrap_or_else(|| panic!("Missing flag name in \"{}\", check from_usage call", u)),
|
||||
short: short,
|
||||
long: long,
|
||||
help: help,
|
||||
|
|
13
src/lib.rs
13
src/lib.rs
|
@ -1242,4 +1242,17 @@ mod tests {
|
|||
assert!(m.is_present("debug"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[should_panic]
|
||||
fn short_flag_misspel() {
|
||||
App::new("short_flag")
|
||||
.arg(Arg::from_usage("-f1, --flag 'some flag'"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[should_panic]
|
||||
fn short_flag_name_missing() {
|
||||
App::new("short_flag")
|
||||
.arg(Arg::from_usage("-f 'some flag'"));
|
||||
}
|
||||
}
|
|
@ -124,8 +124,11 @@ impl<'u> Iterator for UsageParser<'u> {
|
|||
self.e += 1;
|
||||
continue
|
||||
},
|
||||
_ => {
|
||||
None => {
|
||||
return None
|
||||
},
|
||||
Some(c) => {
|
||||
panic!("Usage parser error, unexpected \"{}\" at \"{}\", check from_usage call", c, self.usage);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue