docker/cli · error
%[1]s: '%[2]s' requires at least %[3]d and at most %[4]d…
Error message
%[1]s: '%[2]s' requires at least %[3]d and at most %[4]d %[5]s Usage: %[6]s Run '%[2]s --help' for more information
What it means
Returned by cli.RequiresRangeArgs (required.go:73) when the argument count falls outside [minArgs, maxArgs]. Used by commands accepting a bounded range of positional arguments (e.g. 1..2). The message states both bounds and the usage line.
Solutions
- Count your positional arguments and keep them within the printed [min, max] range.
- Run `<cmd> --help` to see the expected positional signature.
- Move flags-as-values mistakes into proper `--flag value` form.
Example fix
// before: zero positionals for a RequiresRangeArgs(1,2) command docker context use // after: supply the context name docker context use default
Defensive patterns
Strategy: validation
Validate before calling
// Validate within [min,max] before invoking
n := len(positionalArgs)
if n < minArgs || n > maxArgs {
return fmt.Errorf("need between %d and %d positional args, got %d", minArgs, maxArgs, n)
} Prevention
- Confirm the allowed range via --help.
- Provide explicit defaults for optional positionals.
- Check expansion of optional variables in scripts.
When it happens
Trigger: Invoking a command configured with Args: cli.RequiresRangeArgs(min, max) with fewer than min or more than max positional arguments.
Common situations: Supplying zero args, or supplying extra args beyond the allowed range, often due to optional-argument misunderstanding or shell expansion surprises.
Related errors
- %[1]s: unknown command: %[2]s %[3]s Usage: %[4]s Run…
- %[1]s: '%[2]s' accepts no arguments Usage: %[3]s Run…
- %[1]s: '%[2]s' requires at least %[3]d %[4]s Usage: …
- %[1]s: '%[2]s' requires at most %[3]d %[4]s Usage: …
- %[1]s: '%[2]s' requires %[3]d %[4]s Usage: %[5]s Run…
AI-assisted analysis of docker/cli@4f84911bfe (2026-08-07).
Data as JSON: /api/errors/5a5d23360870c593.
Report an issue: GitHub.
Appendix: source
Thrown at cli/required.go:73
}
return fmt.Errorf(
"%[1]s: '%[2]s' requires at most %[3]d %[4]s\n\nUsage: %[5]s\n\nRun '%[2]s --help' for more information",
binName(cmd),
cmd.CommandPath(),
maxArgs,
pluralize("argument", maxArgs),
cmd.UseLine(),
)
}
}
// RequiresRangeArgs returns an error if there is not at least min args and at most max args
func RequiresRangeArgs(minArgs int, maxArgs int) cobra.PositionalArgs {
return func(cmd *cobra.Command, args []string) error {
if len(args) >= minArgs && len(args) <= maxArgs {
return nil
}
return fmt.Errorf(
"%[1]s: '%[2]s' requires at least %[3]d and at most %[4]d %[5]s\n\nUsage: %[6]s\n\nRun '%[2]s --help' for more information",
binName(cmd),
cmd.CommandPath(),
minArgs,
maxArgs,
pluralize("argument", maxArgs),
cmd.UseLine(),
)
}
}
// ExactArgs returns an error if there is not the exact number of args
func ExactArgs(number int) cobra.PositionalArgs {
return func(cmd *cobra.Command, args []string) error {
if len(args) == number {
return nil
}
return fmt.Errorf(View on GitHub (pinned to 4f84911bfe)