mirror of
https://github.com/clap-rs/clap
synced 2025-03-04 23:37:32 +00:00
Merge pull request #3140 from epage/panic
Improve error reporting for bad arg/group/subcommand names
This commit is contained in:
commit
ca48e22827
1 changed files with 16 additions and 2 deletions
|
@ -987,10 +987,17 @@ impl ArgMatches {
|
|||
// Private methods
|
||||
impl ArgMatches {
|
||||
#[inline]
|
||||
#[cfg_attr(debug_assertions, track_caller)]
|
||||
fn get_arg(&self, arg: &Id) -> Option<&MatchedArg> {
|
||||
#[cfg(debug_assertions)]
|
||||
{
|
||||
if *arg != Id::empty_hash() && !self.valid_args.contains(arg) {
|
||||
if *arg == Id::empty_hash() || self.valid_args.contains(arg) {
|
||||
} else if self.valid_subcommands.contains(arg) {
|
||||
panic!(
|
||||
"Subcommand `'{:?}' used where an argument or group name was expected.",
|
||||
arg
|
||||
);
|
||||
} else {
|
||||
panic!(
|
||||
"`'{:?}' is not a name of an argument or a group.\n\
|
||||
Make sure you're using the name of the argument itself \
|
||||
|
@ -1004,10 +1011,17 @@ impl ArgMatches {
|
|||
}
|
||||
|
||||
#[inline]
|
||||
#[cfg_attr(debug_assertions, track_caller)]
|
||||
fn get_subcommand(&self, id: &Id) -> Option<&SubCommand> {
|
||||
#[cfg(debug_assertions)]
|
||||
{
|
||||
if *id != Id::empty_hash() && !self.valid_subcommands.contains(id) {
|
||||
if *id == Id::empty_hash() || self.valid_subcommands.contains(id) {
|
||||
} else if self.valid_args.contains(id) {
|
||||
panic!(
|
||||
"Argument or group `'{:?}' used where a subcommand name was expected.",
|
||||
id
|
||||
);
|
||||
} else {
|
||||
panic!("'{:?}' is not a name of a subcommand.", id);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue