Skip to content

Commit

Permalink
refactor(parser): Clarify arg error
Browse files Browse the repository at this point in the history
  • Loading branch information
epage committed Jan 11, 2024
1 parent 69c0509 commit e47d8a2
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions clap_builder/src/parser/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,17 @@ impl<'cmd> Parser<'cmd> {
&& self.cmd.has_positionals()
&& (arg_os.is_long() || arg_os.is_short());

if !(self.cmd.is_args_conflicts_with_subcommands_set() && valid_arg_found) {
if self.cmd.has_subcommands() {
if self.cmd.is_args_conflicts_with_subcommands_set() && valid_arg_found {
return ClapError::unknown_argument(
self.cmd,
arg_os.display().to_string(),
None,
suggested_trailing_arg,
Usage::new(self.cmd).create_usage_with_title(&[]),
);
}

let candidates = suggestions::did_you_mean(
&arg_os.display().to_string(),
self.cmd.all_subcommand_names(),
Expand All @@ -508,9 +518,7 @@ impl<'cmd> Parser<'cmd> {
}

// If the argument must be a subcommand.
if self.cmd.has_subcommands()
&& (!self.cmd.has_positionals() || self.cmd.is_infer_subcommands_set())
{
if !self.cmd.has_positionals() || self.cmd.is_infer_subcommands_set() {
return ClapError::unrecognized_subcommand(
self.cmd,
arg_os.display().to_string(),
Expand Down

0 comments on commit e47d8a2

Please sign in to comment.