minimumArgs behaves like cobra.MinimumNArgs(n) but reports too few arguments with the command's own usage information.
(n int)
| 32 | // minimumArgs behaves like cobra.MinimumNArgs(n) but reports too few arguments |
| 33 | // with the command's own usage information. |
| 34 | func minimumArgs(n int) cobra.PositionalArgs { |
| 35 | return func(cmd *cobra.Command, args []string) error { |
| 36 | if len(args) >= n { |
| 37 | return nil |
| 38 | } |
| 39 | return argCountError(cmd, fmt.Sprintf("requires at least %d argument(s)", n)) |
| 40 | } |
| 41 | } |
| 42 | |
| 43 | // argCountError assembles the guidance for a wrong argument count. The count the |
| 44 | // user supplied is deliberately not echoed back — it adds nothing they do not |