From e47d8a2a660c97b2f37369e503e781156527304f Mon Sep 17 00:00:00 2001 From: Ed Page Date: Thu, 11 Jan 2024 09:47:00 -0600 Subject: [PATCH] refactor(parser): Clarify arg error --- clap_builder/src/parser/parser.rs | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/clap_builder/src/parser/parser.rs b/clap_builder/src/parser/parser.rs index 93616d68a64..d24d37ade63 100644 --- a/clap_builder/src/parser/parser.rs +++ b/clap_builder/src/parser/parser.rs @@ -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(), @@ -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(),