RequiresRangeArgs returns an error if there is not at least min args and at most max args
(minArgs int, maxArgs int)
| 66 | |
| 67 | // RequiresRangeArgs returns an error if there is not at least min args and at most max args |
| 68 | func RequiresRangeArgs(minArgs int, maxArgs int) cobra.PositionalArgs { |
| 69 | return func(cmd *cobra.Command, args []string) error { |
| 70 | if len(args) >= minArgs && len(args) <= maxArgs { |
| 71 | return nil |
| 72 | } |
| 73 | return fmt.Errorf( |
| 74 | "%[1]s: '%[2]s' requires at least %[3]d and at most %[4]d %[5]s\n\nUsage: %[6]s\n\nRun '%[2]s --help' for more information", |
| 75 | binName(cmd), |
| 76 | cmd.CommandPath(), |
| 77 | minArgs, |
| 78 | maxArgs, |
| 79 | pluralize("argument", maxArgs), |
| 80 | cmd.UseLine(), |
| 81 | ) |
| 82 | } |
| 83 | } |
| 84 | |
| 85 | // ExactArgs returns an error if there is not the exact number of args |
| 86 | func ExactArgs(number int) cobra.PositionalArgs { |
searching dependent graphs…