OnlyValidArgs returns an error if there are any positional args that are not in the `ValidArgs` field of `Command`
(cmd *Command, args []string)
| 49 | // OnlyValidArgs returns an error if there are any positional args that are not in |
| 50 | // the `ValidArgs` field of `Command` |
| 51 | func OnlyValidArgs(cmd *Command, args []string) error { |
| 52 | if len(cmd.ValidArgs) > 0 { |
| 53 | // Remove any description that may be included in ValidArgs. |
| 54 | // A description is following a tab character. |
| 55 | validArgs := make([]string, 0, len(cmd.ValidArgs)) |
| 56 | for _, v := range cmd.ValidArgs { |
| 57 | validArgs = append(validArgs, strings.SplitN(v, "\t", 2)[0]) |
| 58 | } |
| 59 | for _, v := range args { |
| 60 | if !stringInSlice(v, validArgs) { |
| 61 | return fmt.Errorf("invalid argument %q for %q%s", v, cmd.CommandPath(), cmd.findSuggestions(args[0])) |
| 62 | } |
| 63 | } |
| 64 | } |
| 65 | return nil |
| 66 | } |
| 67 | |
| 68 | // ArbitraryArgs never returns an error. |
| 69 | func ArbitraryArgs(cmd *Command, args []string) error { |
nothing calls this directly
no test coverage detected