{"record":{"id":"68993f88f55feab9","repo":"docker/cli","slug":"1-s-2-s-requires-at-least-3-d-4-s-usag","errorCode":null,"errorMessage":"%[1]s: '%[2]s' requires at least %[3]d %[4]s\n\nUsage:  %[5]s\n\nSee '%[2]s --help' for more information","messagePattern":"%\\[1\\]s: '%\\[2\\]s' requires at least %\\[3\\]d %\\[4\\]s\n\nUsage:  %\\[5\\]s\n\nSee '%\\[2\\]s --help' for more information","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cli/required.go","lineNumber":39,"sourceCode":"\t\t\tcmd.UseLine(),\n\t\t)\n\t}\n\n\treturn fmt.Errorf(\n\t\t\"%[1]s: '%[2]s' accepts no arguments\\n\\nUsage:  %[3]s\\n\\nRun '%[2]s --help' for more information\",\n\t\tbinName(cmd),\n\t\tcmd.CommandPath(),\n\t\tcmd.UseLine(),\n\t)\n}\n\n// RequiresMinArgs returns an error if there is not at least min args\nfunc RequiresMinArgs(minArgs int) cobra.PositionalArgs {\n\treturn func(cmd *cobra.Command, args []string) error {\n\t\tif len(args) >= minArgs {\n\t\t\treturn nil\n\t\t}\n\t\treturn fmt.Errorf(\n\t\t\t\"%[1]s: '%[2]s' requires at least %[3]d %[4]s\\n\\nUsage:  %[5]s\\n\\nSee '%[2]s --help' for more information\",\n\t\t\tbinName(cmd),\n\t\t\tcmd.CommandPath(),\n\t\t\tminArgs,\n\t\t\tpluralize(\"argument\", minArgs),\n\t\t\tcmd.UseLine(),\n\t\t)\n\t}\n}\n\n// RequiresMaxArgs returns an error if there is not at most max args\nfunc RequiresMaxArgs(maxArgs int) cobra.PositionalArgs {\n\treturn func(cmd *cobra.Command, args []string) error {\n\t\tif len(args) <= maxArgs {\n\t\t\treturn nil\n\t\t}\n\t\treturn fmt.Errorf(\n\t\t\t\"%[1]s: '%[2]s' requires at most %[3]d %[4]s\\n\\nUsage:  %[5]s\\n\\nRun '%[2]s --help' for more information\",","sourceCodeStart":21,"sourceCodeEnd":57,"githubUrl":"https://github.com/docker/cli/blob/4f84911bfe8811e9b028e4b1fee8e7510be79387/cli/required.go#L21-L57","documentation":"Returned by cli.RequiresMinArgs (required.go:39) when len(args) is below the configured minimum. It is a cobra PositionalArgs validator used by commands that need at least N positional arguments (e.g. `docker tag SRC DST`). Message includes min count, pluralized word, command path, and usage.","triggerScenarios":"Invoking a command configured with Args: cli.RequiresMinArgs(N) with fewer than N positional arguments, e.g. `docker tag only-one` (requires 2).","commonSituations":"Forgetting the destination argument, piping that consumes an expected arg, shell expansion that produced fewer tokens than expected, or misreading docs.","solutions":["Re-read the usage line printed and supply the missing positional argument(s).","If a variable was empty and got dropped, quote it or default it.","Run `<cmd> --help` to confirm the required positional count."],"exampleFix":"// before: missing destination\ndocker tag myimage\n\n// after: both source and destination\ndocker tag myimage myimage:latest","handlingStrategy":"validation","validationCode":"// Ensure at least min args before calling\nif len(positionalArgs) < minArgs {\n    return fmt.Errorf(\"need at least %d positional args, got %d\", minArgs, len(positionalArgs))\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Read --help to learn the required positional count.","Guard scripts for empty variables that expand to missing args.","Use `set -u` to catch unset variables."],"tags":["cli","cobra","usage","arguments"],"backgroundTag":null,"analyzedSha":"4f84911bfe8811e9b028e4b1fee8e7510be79387","analyzedAt":"2026-08-07T12:15:29.814Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}