ExactArgs returns an error if there are not exactly n args.
(n int)
| 35 | |
| 36 | // ExactArgs returns an error if there are not exactly n args. |
| 37 | func ExactArgs(n int) cobra.PositionalArgs { |
| 38 | return func(cmd *cobra.Command, args []string) error { |
| 39 | if len(args) != n { |
| 40 | return fmt.Errorf( |
| 41 | "%q requires %d %s\n\nUsage: %s", |
| 42 | cmd.CommandPath(), |
| 43 | n, |
| 44 | pluralize("argument", n), |
| 45 | cmd.UseLine(), |
| 46 | ) |
| 47 | } |
| 48 | return nil |
| 49 | } |
| 50 | } |
| 51 | |
| 52 | // MaximumNArgs returns an error if there are more than N args. |
| 53 | func MaximumNArgs(n int) cobra.PositionalArgs { |
searching dependent graphs…