{"record":{"id":"22f8a23584ef70ae","repo":"siyuan-note/siyuan","slug":"id-is-required-22f8a2","errorCode":null,"errorMessage":"--id is required","messagePattern":"--id is required","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/cli/cmd/export.go","lineNumber":39,"sourceCode":"\t\"os\"\n\n\t\"github.com/siyuan-note/siyuan/kernel/model\"\n\n\t\"github.com/spf13/cobra\"\n)\n\nvar exportCmd = &cobra.Command{\n\tUse:   \"export\",\n\tShort: \"Export documents\",\n}\n\nvar exportMdCmd = &cobra.Command{\n\tUse:   \"md --id <id>\",\n\tShort: \"Export as Markdown\",\n\tRunE: func(cmd *cobra.Command, args []string) error {\n\t\tid, _ := cmd.Flags().GetString(\"id\")\n\t\tif id == \"\" {\n\t\t\treturn fmt.Errorf(\"--id is required\")\n\t\t}\n\n\t\toutput, _ := cmd.Flags().GetString(\"output\")\n\t\tif dryRun && output != \"\" {\n\t\t\tfmt.Printf(\"[dry-run] Would export markdown for document %s to %s\\n\", id, output)\n\t\t\treturn nil\n\t\t}\n\n\t\t_, content := model.ExportMarkdownContent(id, 4, 0, true, false, false, false, false)\n\t\tif output != \"\" {\n\t\t\treturn os.WriteFile(output, []byte(content), 0644)\n\t\t}\n\t\tfmt.Print(content)\n\t\treturn nil\n\t},\n}\n\nvar exportHTMLCmd = &cobra.Command{","sourceCodeStart":21,"sourceCodeEnd":57,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/251596fc0de2f9528c00c224252fd073a99973f4/kernel/cli/cmd/export.go#L21-L57","documentation":"The `export md` cobra subcommand requires the --id flag identifying the document to export as Markdown. The handler returns this error when --id is empty, before the dry-run check and before calling model.ExportMarkdownContent. The --output flag is optional (omit it to print to stdout).","triggerScenarios":"Running `siyuan export md` with no flags; passing `--id \"\"`; scripting with an unset ID variable; misspelling the flag; passing only --output.","commonSituations":"Forgetting the ID; copy-paste leaving a placeholder; shell variable empty for an iteration; assuming export of the whole notebook (not supported by this subcommand); confusing notebook ID with document ID.","solutions":["Supply the document ID: `siyuan export md --id <id>`.","Optionally add `--output file.md` to write to a file instead of stdout.","Look up the ID via `document list` or `document search`.","Guard the ID variable in scripts.","Verify the flag with `siyuan export md --help`."],"exampleFix":"// before\nsiyuan export md --output notes.md\n// after\nsiyuan export md --id 20240101000000-abc1234 --output notes.md","handlingStrategy":"validation","validationCode":"[ -n \"$DOC_ID\" ] || { echo '--id is required' >&2; exit 2; }\nsiyuan export md --id \"$DOC_ID\" --output \"$OUT\"","typeGuard":null,"tryCatchPattern":"if ! siyuan export md --id \"$DOC_ID\" --output \"$OUT\" 2>err.txt; then\n  grep -q 'id is required' err.txt && echo \"pass --id <docId>\" >&2\n  exit 1\nfi","preventionTips":["Resolve the ID via list/search before exporting.","Use `set -u`.","Omit --output to stream to stdout for quick checks."],"tags":["cli","cobra","flag-validation","export","markdown","document","go"],"backgroundTag":null,"analyzedSha":"251596fc0de2f9528c00c224252fd073a99973f4","analyzedAt":"2026-08-12T21:18:37.123Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}