{"record":{"id":"d467c6e74696a7ac","repo":"docker/cli","slug":"1-s-2-s-accepts-no-arguments-usage-3-s","errorCode":null,"errorMessage":"%[1]s: '%[2]s' accepts no arguments\n\nUsage:  %[3]s\n\nRun '%[2]s --help' for more information","messagePattern":"%\\[1\\]s: '%\\[2\\]s' accepts no arguments\n\nUsage:  %\\[3\\]s\n\nRun '%\\[2\\]s --help' for more information","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cli/required.go","lineNumber":25,"sourceCode":")\n\n// NoArgs validates args and returns an error if there are any args\nfunc NoArgs(cmd *cobra.Command, args []string) error {\n\tif len(args) == 0 {\n\t\treturn nil\n\t}\n\n\tif cmd.HasSubCommands() {\n\t\treturn fmt.Errorf(\n\t\t\t\"%[1]s: unknown command: %[2]s %[3]s\\n\\nUsage:  %[4]s\\n\\nRun '%[2]s --help' for more information\",\n\t\t\tbinName(cmd),\n\t\t\tcmd.CommandPath(),\n\t\t\targs[0],\n\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,","sourceCodeStart":7,"sourceCodeEnd":43,"githubUrl":"https://github.com/docker/cli/blob/4f84911bfe8811e9b028e4b1fee8e7510be79387/cli/required.go#L7-L43","documentation":"Returned by cli.NoArgs (required.go:25) when the command received positional arguments AND it has no subcommands. This means the command genuinely accepts zero positional args (e.g. a status/info command) and the user supplied extras. The message includes binary name, command path, and usage.","triggerScenarios":"A cobra command with Args: cli.NoArgs and no child commands invoked with one or more positional arguments, e.g. `docker version extra` where version takes none.","commonSituations":"Passing a flag value without the flag (so it becomes positional), a script appending unexpected arguments, or misunderstanding that a command is purely flag-driven.","solutions":["Remove the extra positional arguments; check `--help` to confirm the command takes none.","If you meant to pass a value, attach it to the correct flag (e.g. `--format ...`).","Audit wrapper scripts that append `$@` unconditionally."],"exampleFix":"// before: stray positional\ndocker version myhost\n\n// after: no positional args\ndocker version","handlingStrategy":"validation","validationCode":"// Reject extra positionals before invoking a NoArgs command\nif len(args) > 0 {\n    return fmt.Errorf(\"%s takes no positional arguments\", cmdPath)\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Check a command's --help to confirm it is flag-only.","Quote flag values so they are not mistaken for positionals.","Avoid blind `$@` forwarding in wrappers."],"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"}