(program: Command, context: CliContext)
| 11 | } |
| 12 | |
| 13 | export function registerFetchCommand(program: Command, context: CliContext): void { |
| 14 | program |
| 15 | .command('fetch') |
| 16 | .description('Fetch a Microsoft Learn document in markdown-friendly form.') |
| 17 | .argument('<url>', 'Microsoft Learn document URL.') |
| 18 | .option('--section <heading>', 'Return only the matching markdown section.') |
| 19 | .option('--max-chars <number>', 'Truncate the final rendered output.', parsePositiveInteger) |
| 20 | .action(async (url: string, options: FetchCommandOptions) => { |
| 21 | const endpoint = resolveEndpoint(program.opts<{ endpoint?: string }>().endpoint, context.env); |
| 22 | const normalizedUrl = normalizeUrl(url); |
| 23 | const client = context.createClient({ endpoint }); |
| 24 | |
| 25 | try { |
| 26 | const markdown = await client.fetchDocument(normalizedUrl); |
| 27 | const sectionFiltered = options.section ? extractMarkdownSection(markdown, options.section) : markdown; |
| 28 | const finalContent = truncateOutput(sectionFiltered, options.maxChars); |
| 29 | context.writeOut(ensureTrailingNewline(finalContent)); |
| 30 | } finally { |
| 31 | await client.close(); |
| 32 | } |
| 33 | }); |
| 34 | } |
no test coverage detected