{"record":{"id":"a01005799b32ca14","repo":"caddyserver/caddy","slug":"designated-output-directory-and-specified-section","errorCode":null,"errorMessage":"designated output directory and specified section are required","messagePattern":"designated output directory and specified section are required","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/commands.go","lineNumber":470,"sourceCode":"\n\tdefaultFactory.Use(func(rootCmd *cobra.Command) {\n\t\tmanpageCommand := Command{\n\t\t\tName:  \"manpage\",\n\t\t\tUsage: \"--directory <path>\",\n\t\t\tShort: \"Generates the manual pages for Caddy commands\",\n\t\t\tLong: `\nGenerates the manual pages for Caddy commands into the designated directory\ntagged into section 8 (System Administration).\n\nThe manual page files are generated into the directory specified by the\nargument of --directory. If the directory does not exist, it will be created.\n`,\n\t\t\tCobraFunc: func(cmd *cobra.Command) {\n\t\t\t\tcmd.Flags().StringP(\"directory\", \"o\", \"\", \"The output directory where the manpages are generated\")\n\t\t\t\tcmd.RunE = WrapCommandFuncForCobra(func(fl Flags) (int, error) {\n\t\t\t\t\tdir := strings.TrimSpace(fl.String(\"directory\"))\n\t\t\t\t\tif dir == \"\" {\n\t\t\t\t\t\treturn caddy.ExitCodeFailedQuit, fmt.Errorf(\"designated output directory and specified section are required\")\n\t\t\t\t\t}\n\t\t\t\t\tif err := os.MkdirAll(dir, 0o755); err != nil {\n\t\t\t\t\t\treturn caddy.ExitCodeFailedQuit, err\n\t\t\t\t\t}\n\t\t\t\t\tif err := doc.GenManTree(rootCmd, &doc.GenManHeader{\n\t\t\t\t\t\tTitle:   \"Caddy\",\n\t\t\t\t\t\tSection: \"8\", // https://en.wikipedia.org/wiki/Man_page#Manual_sections\n\t\t\t\t\t}, dir); err != nil {\n\t\t\t\t\t\treturn caddy.ExitCodeFailedQuit, err\n\t\t\t\t\t}\n\t\t\t\t\treturn caddy.ExitCodeSuccess, nil\n\t\t\t\t})\n\t\t\t},\n\t\t}\n\n\t\t// source: https://github.com/spf13/cobra/blob/6dec1ae26659a130bdb4c985768d1853b0e1bc06/site/content/completions/_index.md\n\t\tcompletionCommand := Command{\n\t\t\tName:  \"completion\",","sourceCodeStart":452,"sourceCodeEnd":488,"githubUrl":"https://github.com/caddyserver/caddy/blob/50e54ee279aa1e504fe218ca49ab6ae16c100410/cmd/commands.go#L452-L488","documentation":"From the hidden 'manpage' command: the --directory/-o flag is required to know where to emit the generated man pages, and it was empty or whitespace after trimming. Section is hardcoded to 8, so only the directory is actually user-supplied.","triggerScenarios":"Running 'caddy manpage' without -o, or with -o \" \" (whitespace-only).","commonSituations":"Packaging scripts invoking 'caddy manpage' and expecting files in the CWD; users assuming a default output directory exists.","solutions":["Pass an explicit output directory: caddy manpage --directory /usr/local/share/man/man8","In scripts, fail fast if the directory variable is empty before calling the command"],"exampleFix":"# before\ncaddy manpage\n\n# after\ncaddy manpage --directory /tmp/caddy-man","handlingStrategy":"validation","validationCode":"# Fail fast in scripts when the target directory is unset:\n: \"${MAN_DIR:?MAN_DIR must be set}\"\ncaddy manpage --directory \"$MAN_DIR\"","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Treat --directory as mandatory in packaging scripts","Shell parameter expansion with :? catches empty vars before the CLI does"],"tags":["cli","manpage","missing-flag"],"backgroundTag":null,"analyzedSha":"50e54ee279aa1e504fe218ca49ab6ae16c100410","analyzedAt":"2026-08-15T09:20:21.641Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}