{"record":{"id":"af8170a32e63e633","repo":"docker/cli","slug":"1-s-2-s-requires-3-d-4-s-usage-5-s","errorCode":null,"errorMessage":"%[1]s: '%[2]s' requires %[3]d %[4]s\n\nUsage:  %[5]s\n\nRun '%[2]s --help' for more information","messagePattern":"%\\[1\\]s: '%\\[2\\]s' requires %\\[3\\]d %\\[4\\]s\n\nUsage:  %\\[5\\]s\n\nRun '%\\[2\\]s --help' for more information","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cli/required.go","lineNumber":91,"sourceCode":"\t\treturn fmt.Errorf(\n\t\t\t\"%[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\",\n\t\t\tbinName(cmd),\n\t\t\tcmd.CommandPath(),\n\t\t\tminArgs,\n\t\t\tmaxArgs,\n\t\t\tpluralize(\"argument\", maxArgs),\n\t\t\tcmd.UseLine(),\n\t\t)\n\t}\n}\n\n// ExactArgs returns an error if there is not the exact number of args\nfunc ExactArgs(number int) cobra.PositionalArgs {\n\treturn func(cmd *cobra.Command, args []string) error {\n\t\tif len(args) == number {\n\t\t\treturn nil\n\t\t}\n\t\treturn fmt.Errorf(\n\t\t\t\"%[1]s: '%[2]s' requires %[3]d %[4]s\\n\\nUsage:  %[5]s\\n\\nRun '%[2]s --help' for more information\",\n\t\t\tbinName(cmd),\n\t\t\tcmd.CommandPath(),\n\t\t\tnumber,\n\t\t\tpluralize(\"argument\", number),\n\t\t\tcmd.UseLine(),\n\t\t)\n\t}\n}\n\n// binName returns the name of the binary / root command (usually 'docker').\nfunc binName(cmd *cobra.Command) string {\n\treturn cmd.Root().Name()\n}\n\n//nolint:unparam\nfunc pluralize(word string, number int) string {\n\tif number == 1 {","sourceCodeStart":73,"sourceCodeEnd":109,"githubUrl":"https://github.com/docker/cli/blob/4f84911bfe8811e9b028e4b1fee8e7510be79387/cli/required.go#L73-L109","documentation":"Returned by cli.ExactArgs (required.go:91) when len(args) is not exactly the required number. Used by commands needing a precise count of positional arguments (e.g. exactly 2 for tag/push-with-dest). The message states the exact number, pluralized, plus usage.","triggerScenarios":"Invoking a command configured with Args: cli.ExactArgs(N) with any count other than N positional arguments.","commonSituations":"Dropping one of a pair of required args, adding an extra trailing arg, or a script conditionally omitting an argument.","solutions":["Provide exactly N positional arguments as printed.","Confirm required vs optional positionals via `<cmd> --help`.","Validate argument count in your wrapper script before invoking docker."],"exampleFix":"// before: wrong count for ExactArgs(2)\ndocker tag src dst extra\n\n// after: exactly two\ndocker tag src dst","handlingStrategy":"validation","validationCode":"// Require exact count before invoking\nif len(positionalArgs) != exact {\n    return fmt.Errorf(\"need exactly %d positional args, got %d\", exact, len(positionalArgs))\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Map out required-vs-optional positionals from --help.","Make wrapper scripts assert arg count before calling docker.","Avoid trailing tokens that inflate the count."],"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"}