{"record":{"id":"e42e52f11d96e86b","repo":"jackwener/OpenCLI","slug":"output-md-text-format","errorCode":null,"errorMessage":"--output 只接受 md 或 text，收到：${format}","messagePattern":"--output 只接受 md 或 text，收到：(.+?)","errorType":"validation","errorClass":"ArgumentError","httpStatus":null,"severity":"warning","filePath":"clis/mubu/doc.js","lineNumber":22,"sourceCode":"\ncli({\n  site: 'mubu',\n  name: 'doc',\n    access: 'read',\n  description: '读取幕布文档内容（默认输出 Markdown，可用 --output text 输出纯文本）',\n  domain: 'mubu.com',\n  strategy: Strategy.COOKIE,\n  defaultFormat: 'plain',\n  args: [\n    { name: 'id', positional: true, required: true, help: '文档 ID' },\n    { name: 'output', default: 'md', help: '输出格式：md（默认，缩进列表 Markdown，适合导入 Obsidian）或 text（纯文本，适合终端阅读）' },\n  ],\n  columns: ['content'],\n  func: async (page, kwargs) => {\n    const docId = kwargs.id;\n    const format = kwargs.output;\n    if (format !== 'md' && format !== 'text') {\n      throw new ArgumentError(`--output 只接受 md 或 text，收到：${format}`);\n    }\n\n    await page.goto('https://mubu.com/app');\n\n    const data = await mubuPost(page, '/document/edit/get', { docId });\n\n    let nodes = [];\n    try {\n      const def = JSON.parse(data.definition);\n      nodes = def.nodes ?? [];\n    } catch {\n      return [{ content: data.name }];\n    }\n\n    const output = format === 'md' ? nodesToMarkdown(nodes) : nodesToText(nodes);\n\n    return [{ content: output }];\n  },","sourceCodeStart":4,"sourceCodeEnd":40,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/mubu/doc.js#L4-L40","documentation":"The mubu document export command in clis/mubu/doc.js validates the --output flag before driving the browser. Only 'md' (Markdown) and 'text' (plain text) are supported; any other value throws an ArgumentError with a Chinese message meaning '--output only accepts md or text, received: <format>'.","triggerScenarios":"Passing --output with any value other than exactly 'md' or 'text' — e.g. --output markdown, --output html, --output pdf, --output MD (case-sensitive exact match), or an undefined/null value reaching the check.","commonSituations":"Typing long-form format names ('markdown' instead of 'md'); assuming PDF/HTML export is supported when it is not; uppercase values like 'MD' failing the exact string comparison; scripts built against a different CLI version that accepted more formats.","solutions":["Use --output md to export the document as Markdown.","Use --output text to export as plain text.","Check spelling and case: only lowercase 'md' and 'text' are accepted.","If another format is needed, export as md and convert locally (e.g. pandoc md -> html/pdf)."],"exampleFix":"// before\nmubu doc get --id 123456 --output markdown\n\n// after\nmubu doc get --id 123456 --output md","handlingStrategy":"validation","validationCode":"function assertOutputFormat(fmt) {\n  const allowed = new Set(['md', 'text']);\n  if (!allowed.has(fmt)) throw new Error(`--output must be 'md' or 'text', got: ${fmt}`);\n  return fmt;\n}\n// call before invoking: assertOutputFormat(kwargs.output)","typeGuard":"function isSupportedOutputFormat(v) {\n  return v === 'md' || v === 'text';\n}","tryCatchPattern":"try {\n  await exportDoc({ id, output: fmt });\n} catch (e) {\n  if (/只接受 md 或 text/.test(e.message)) {\n    console.error(\"Unsupported --output value; use 'md' or 'text'\");\n    process.exitCode = 2;\n  } else { throw e; }\n}","preventionTips":["Only pass the exact lowercase literals 'md' or 'text' to --output.","Normalize user input with .toLowerCase().trim() and reject anything else early.","Do not assume PDF/HTML export exists — convert from md locally with pandoc.","Validate flags in scripts before invoking the CLI to fail fast."],"tags":["cli","argument-validation","export"],"backgroundTag":"invalid-argument-value","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}