AtLeastNArgs is a validator for commands to print an error with a custom message followed by usage, flags and available commands when too few argument(s) are provided
(n int)
| 54 | // AtLeastNArgs is a validator for commands to print an error with a custom message |
| 55 | // followed by usage, flags and available commands when too few argument(s) are provided |
| 56 | func AtLeastNArgs(n int) cobra.PositionalArgs { |
| 57 | argument := "argument" |
| 58 | if n > 1 { |
| 59 | argument = argument + "s" |
| 60 | } |
| 61 | |
| 62 | return func(cmd *cobra.Command, args []string) error { |
| 63 | if len(args) < n { |
| 64 | msg := fmt.Sprintf("`%s` requires at least %d %s.", cmd.CommandPath(), n, argument) |
| 65 | |
| 66 | return cmdutil.FlagErrorf("%s", msg) |
| 67 | } |
| 68 | |
| 69 | return nil |
| 70 | } |
| 71 | } |
nothing calls this directly
no test coverage detected