ExactArgs returns an error if there is not the exact number of args
(number int)
| 84 | |
| 85 | // ExactArgs returns an error if there is not the exact number of args |
| 86 | func ExactArgs(number int) cobra.PositionalArgs { |
| 87 | return func(cmd *cobra.Command, args []string) error { |
| 88 | if len(args) == number { |
| 89 | return nil |
| 90 | } |
| 91 | return fmt.Errorf( |
| 92 | "%[1]s: '%[2]s' requires %[3]d %[4]s\n\nUsage: %[5]s\n\nRun '%[2]s --help' for more information", |
| 93 | binName(cmd), |
| 94 | cmd.CommandPath(), |
| 95 | number, |
| 96 | pluralize("argument", number), |
| 97 | cmd.UseLine(), |
| 98 | ) |
| 99 | } |
| 100 | } |
| 101 | |
| 102 | // binName returns the name of the binary / root command (usually 'docker'). |
| 103 | func binName(cmd *cobra.Command) string { |
searching dependent graphs…