RequiresMaxArgs returns an error if there is not at most max args
(maxArgs int)
| 49 | |
| 50 | // RequiresMaxArgs returns an error if there is not at most max args |
| 51 | func RequiresMaxArgs(maxArgs int) cobra.PositionalArgs { |
| 52 | return func(cmd *cobra.Command, args []string) error { |
| 53 | if len(args) <= maxArgs { |
| 54 | return nil |
| 55 | } |
| 56 | return fmt.Errorf( |
| 57 | "%[1]s: '%[2]s' requires at most %[3]d %[4]s\n\nUsage: %[5]s\n\nRun '%[2]s --help' for more information", |
| 58 | binName(cmd), |
| 59 | cmd.CommandPath(), |
| 60 | maxArgs, |
| 61 | pluralize("argument", maxArgs), |
| 62 | cmd.UseLine(), |
| 63 | ) |
| 64 | } |
| 65 | } |
| 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 { |
searching dependent graphs…