From 01ce53c87a3cba9b3225049e20751dbe886ab108 Mon Sep 17 00:00:00 2001 From: Dong Gang Date: Sat, 11 Jul 2020 15:38:54 +0800 Subject: [PATCH] fix(args): Correct `legacyArgs` logical errors Close #1156 Signed-off-by: Dong Gang --- args.go | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/args.go b/args.go index 70e9b2629..a12999609 100644 --- a/args.go +++ b/args.go @@ -9,16 +9,15 @@ type PositionalArgs func(cmd *Command, args []string) error // Legacy arg validation has the following behaviour: // - root commands with no subcommands can take arbitrary arguments -// - root commands with subcommands will do subcommand validity checking -// - subcommands will always accept arbitrary arguments +// - commands with subcommands cannot take any arguments func legacyArgs(cmd *Command, args []string) error { // no subcommand, always take args if !cmd.HasSubCommands() { return nil } - // root command with subcommands, do subcommand checking. - if !cmd.HasParent() && len(args) > 0 { + // root command with subcommands, the args should be empty. + if cmd.HasSubCommands() && len(args) > 0 { return fmt.Errorf("unknown command %q for %q%s", args[0], cmd.CommandPath(), cmd.findSuggestions(args[0])) } return nil