RequiresMinArgs returns an error if there is not at least min args
(minArgs int)
| 32 | |
| 33 | // RequiresMinArgs returns an error if there is not at least min args |
| 34 | func RequiresMinArgs(minArgs int) cobra.PositionalArgs { |
| 35 | return func(cmd *cobra.Command, args []string) error { |
| 36 | if len(args) >= minArgs { |
| 37 | return nil |
| 38 | } |
| 39 | return fmt.Errorf( |
| 40 | "%[1]s: '%[2]s' requires at least %[3]d %[4]s\n\nUsage: %[5]s\n\nSee '%[2]s --help' for more information", |
| 41 | binName(cmd), |
| 42 | cmd.CommandPath(), |
| 43 | minArgs, |
| 44 | pluralize("argument", minArgs), |
| 45 | cmd.UseLine(), |
| 46 | ) |
| 47 | } |
| 48 | } |
| 49 | |
| 50 | // RequiresMaxArgs returns an error if there is not at most max args |
| 51 | func RequiresMaxArgs(maxArgs int) cobra.PositionalArgs { |
searching dependent graphs…