{"record":{"id":"f37edceb8d48ba35","repo":"ory/hydra","slug":"command-expects-one-argument-which-is-the-path-to","errorCode":null,"errorMessage":"command expects one argument which is the path to the output directory","messagePattern":"command expects one argument which is the path to the output directory","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"oryx/clidoc/generate.go","lineNumber":19,"sourceCode":"package clidoc\n\nimport (\n\t\"bytes\"\n\t\"fmt\"\n\t\"io\"\n\t\"os\"\n\t\"path/filepath\"\n\t\"strings\"\n\n\t\"github.com/pkg/errors\"\n\n\t\"github.com/spf13/cobra\"\n)\n\n// Generate generates markdown documentation for a cobra command and its children.\nfunc Generate(cmd *cobra.Command, args []string) error {\n\tif len(args) != 1 {\n\t\treturn errors.New(\"command expects one argument which is the path to the output directory\")\n\t}\n\n\treturn generate(cmd, args[0])\n}\n\nfunc trimExt(s string) string {\n\treturn strings.ReplaceAll(strings.TrimSuffix(s, filepath.Ext(s)), \"_\", \"-\")\n}\n\nfunc generate(cmd *cobra.Command, dir string) error {\n\tcmd.DisableAutoGenTag = true\n\tfor _, c := range cmd.Commands() {\n\t\tif !c.IsAvailableCommand() || c.IsAdditionalHelpTopicCommand() {\n\t\t\tcontinue\n\t\t}\n\t\tif err := generate(c, dir); err != nil {\n\t\t\treturn err\n\t\t}","sourceCodeStart":1,"sourceCodeEnd":37,"githubUrl":"https://github.com/ory/hydra/blob/4174065ffb052799890f7480f5360a877a67ffc1/oryx/clidoc/generate.go#L1-L37","documentation":"This error is returned by the clidoc Generate cobra command when the number of positional arguments is not exactly one. The command generates markdown documentation for a command tree and requires exactly one argument: the path to the output directory.","triggerScenarios":"Running the generated CLI's docs command with zero arguments or more than one argument — `len(args) != 1` in Generate (oryx/clidoc/generate.go:19).","commonSituations":"Users run `myapp docs` without the output path; shell scripts pass extra flags interpreted as positional args; copy-pasted examples quote paths into two arguments; forgetting that the command takes a directory, not a file.","solutions":["Run the command with exactly one argument: the output directory path, e.g. `myapp docs ./docs/cli`.","Quote paths containing spaces so they count as one argument.","Create the output directory beforehand if the generator does not mkdir it.","Check `myapp docs --help` for the exact usage string."],"exampleFix":"# before\n$ myapp docs\nError: command expects one argument which is the path to the output directory\n# after\n$ myapp docs ./docs/commands","handlingStrategy":"validation","validationCode":"// wrapper that enforces the argument before invoking the command\nfunc mustDocsArgs(args []string) error {\n    if len(args) != 1 {\n        return fmt.Errorf(\"usage: myapp docs <output-dir>\")\n    }\n    if fi, err := os.Stat(args[0]); err != nil || !fi.IsDir() {\n        return fmt.Errorf(\"output directory %q does not exist\", args[0])\n    }\n    return nil\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Quote paths with spaces so they count as one argument","Add a cobra Args: cobra.ExactArgs(1) validator to the command definition","Check --help output before running unfamiliar doc commands","Pre-create the output directory in scripts"],"tags":["cli","cobra","argument-error","documentation"],"backgroundTag":"invalid-cli-argument","analyzedSha":"4174065ffb052799890f7480f5360a877a67ffc1","analyzedAt":"2026-09-03T14:52:41.581Z","contentChangedAt":"2026-09-03T14:52:41.581Z","schemaVersion":2},"datasetVersion":"2026-09-10T17:17:09.494Z"}