(specId?: string, options: ShowOptions = {})
| 78 | } |
| 79 | |
| 80 | async show(specId?: string, options: ShowOptions = {}): Promise<void> { |
| 81 | if (!specId) { |
| 82 | const canPrompt = isInteractive(options); |
| 83 | const specIds = await getSpecIds(this.rootPath ?? process.cwd()); |
| 84 | if (canPrompt && specIds.length > 0) { |
| 85 | const { select } = await import('@inquirer/prompts'); |
| 86 | specId = await select({ |
| 87 | message: 'Select a spec to show', |
| 88 | choices: specIds.map(id => ({ name: id, value: id })), |
| 89 | }); |
| 90 | } else { |
| 91 | throw new Error('Missing required argument <spec-id>'); |
| 92 | } |
| 93 | } |
| 94 | |
| 95 | const specPath = join(this.specsDir, specId, 'spec.md'); |
| 96 | if (!existsSync(specPath)) { |
| 97 | // Root-aware callers get the absolute path; the cwd-based noun form |
| 98 | // keeps its historical forward-slash relative message on all platforms. |
| 99 | const displayPath = this.rootPath ? specPath : `openspec/specs/${specId}/spec.md`; |
| 100 | throw new Error(`Spec '${specId}' not found at ${displayPath}`); |
| 101 | } |
| 102 | |
| 103 | if (options.json) { |
| 104 | if (options.requirements && options.requirement) { |
| 105 | throw new Error('Options --requirements and --requirement cannot be used together'); |
| 106 | } |
| 107 | const parsed = parseSpecFromFile(specPath, specId); |
| 108 | const filtered = filterSpec(parsed, options); |
| 109 | const output = { |
| 110 | id: specId, |
| 111 | title: parsed.name, |
| 112 | overview: parsed.overview, |
| 113 | requirementCount: filtered.requirements.length, |
| 114 | requirements: filtered.requirements, |
| 115 | metadata: parsed.metadata ?? { version: '1.0.0', format: 'openspec' as const }, |
| 116 | ...(options.rootOutput ? { root: options.rootOutput } : {}), |
| 117 | }; |
| 118 | console.log(JSON.stringify(output, null, 2)); |
| 119 | return; |
| 120 | } |
| 121 | printSpecTextRaw(specPath); |
| 122 | } |
| 123 | } |
| 124 | |
| 125 | export function registerSpecCommand(rootProgram: typeof program) { |
no test coverage detected