ExactArgs is the same as ExactArgsWithMsg but displays a default error message
(n int)
| 35 | // ExactArgs is the same as ExactArgsWithMsg but displays |
| 36 | // a default error message |
| 37 | func ExactArgs(n int) cobra.PositionalArgs { |
| 38 | argument := "argument" |
| 39 | if n > 1 { |
| 40 | argument = argument + "s" |
| 41 | } |
| 42 | |
| 43 | return func(cmd *cobra.Command, args []string) error { |
| 44 | extractArgs := ExactArgsWithMsg(n, fmt.Sprintf("`%s` requires exactly %d %s.", |
| 45 | cmd.CommandPath(), |
| 46 | n, |
| 47 | argument, |
| 48 | )) |
| 49 | |
| 50 | return extractArgs(cmd, args) |
| 51 | } |
| 52 | } |
| 53 | |
| 54 | // AtLeastNArgs is a validator for commands to print an error with a custom message |
| 55 | // followed by usage, flags and available commands when too few argument(s) are provided |
no test coverage detected