{"record":{"id":"5b0314fdcb6ad6c9","repo":"docker/cli","slug":"1-s-unknown-command-2-s-3-s-usage-4-s","errorCode":null,"errorMessage":"%[1]s: unknown command: %[2]s %[3]s\n\nUsage:  %[4]s\n\nRun '%[2]s --help' for more information","messagePattern":"%\\[1\\]s: unknown command: %\\[2\\]s %\\[3\\]s\n\nUsage:  %\\[4\\]s\n\nRun '%\\[2\\]s --help' for more information","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cli/required.go","lineNumber":16,"sourceCode":"package cli\n\nimport (\n\t\"fmt\"\n\n\t\"github.com/spf13/cobra\"\n)\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 {","sourceCodeStart":1,"sourceCodeEnd":34,"githubUrl":"https://github.com/docker/cli/blob/4f84911bfe8811e9b028e4b1fee8e7510be79387/cli/required.go#L1-L34","documentation":"Returned by cli.NoArgs (required.go:16) when the command received positional arguments AND cmd.HasSubCommands() is true. It is the cobra Args validator telling the user the first positional token was not recognized as a subcommand of a command that has subcommands. The format includes the binary name, command path, the offending token, and the usage line.","triggerScenarios":"A cobra command configured with Args: cli.NoArgs that also defines subcommands receives an unknown first argument — e.g. `docker foo bar` where `foo` has subcommands but `bar` is not one. The validator fires before cobra's own subcommand dispatch message.","commonSituations":"Typos in subcommand names, using a subcommand from a newer docker version on an older binary, aliasing issues, or scripts passing an unexpected positional token to a parent command.","solutions":["Run `<command path> --help` to list valid subcommands and correct the typo.","Upgrade/downgrade docker to match the subcommand you expect.","Check shell aliases and scripts that prepend arguments.","Quote or reorder arguments so flags come before positional tokens."],"exampleFix":"// before: typo'd subcommand\ndocker image buld -t x .\n\n// after: correct subcommand\ndocker image build -t x .","handlingStrategy":"validation","validationCode":"// Validate the requested subcommand exists before invoking\ncmd, _, e := rootCmd.Find(append([]string{parent}, args...))\nif e != nil || cmd == nil || cmd == rootCmd && len(args) > 0 {\n    return fmt.Errorf(\"unknown subcommand %q; see %s --help\", args[0], parent)\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always provide --help discovery for parent commands.","Pin docker versions in scripts to match available subcommands.","Validate subcommand names in wrappers before calling docker."],"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"}