legacyArgs 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
(cmd *Command, args []string)
| 26 | // - root commands with subcommands will do subcommand validity checking |
| 27 | // - subcommands will always accept arbitrary arguments |
| 28 | func legacyArgs(cmd *Command, args []string) error { |
| 29 | // no subcommand, always take args |
| 30 | if !cmd.HasSubCommands() { |
| 31 | return nil |
| 32 | } |
| 33 | |
| 34 | // root command with subcommands, do subcommand checking. |
| 35 | if !cmd.HasParent() && len(args) > 0 { |
| 36 | return fmt.Errorf("unknown command %q for %q%s", args[0], cmd.CommandPath(), cmd.findSuggestions(args[0])) |
| 37 | } |
| 38 | return nil |
| 39 | } |
| 40 | |
| 41 | // NoArgs returns an error if any args are included. |
| 42 | func NoArgs(cmd *Command, args []string) error { |
no test coverage detected