NoArgs validates args and returns an error if there are any args
(cmd *cobra.Command, args []string)
| 8 | |
| 9 | // NoArgs validates args and returns an error if there are any args |
| 10 | func NoArgs(cmd *cobra.Command, args []string) error { |
| 11 | if len(args) == 0 { |
| 12 | return nil |
| 13 | } |
| 14 | |
| 15 | if cmd.HasSubCommands() { |
| 16 | return fmt.Errorf( |
| 17 | "%[1]s: unknown command: %[2]s %[3]s\n\nUsage: %[4]s\n\nRun '%[2]s --help' for more information", |
| 18 | binName(cmd), |
| 19 | cmd.CommandPath(), |
| 20 | args[0], |
| 21 | cmd.UseLine(), |
| 22 | ) |
| 23 | } |
| 24 | |
| 25 | return fmt.Errorf( |
| 26 | "%[1]s: '%[2]s' accepts no arguments\n\nUsage: %[3]s\n\nRun '%[2]s --help' for more information", |
| 27 | binName(cmd), |
| 28 | cmd.CommandPath(), |
| 29 | cmd.UseLine(), |
| 30 | ) |
| 31 | } |
| 32 | |
| 33 | // RequiresMinArgs returns an error if there is not at least min args |
| 34 | func RequiresMinArgs(minArgs int) cobra.PositionalArgs { |
nothing calls this directly
no test coverage detected
searching dependent graphs…