(program: Command, context: CliContext)
| 11 | } |
| 12 | |
| 13 | export function registerCodeSearchCommand(program: Command, context: CliContext): void { |
| 14 | program |
| 15 | .command('code-search') |
| 16 | .description('Search Microsoft Learn code samples through the Learn MCP server.') |
| 17 | .argument('<query>', 'Search query.') |
| 18 | .option('--language <name>', 'Preferred language filter to pass to Learn.') |
| 19 | .option('--json', 'Output raw JSON instead of formatted text.') |
| 20 | .action(async (query: string, options: CodeSearchCommandOptions) => { |
| 21 | const endpoint = resolveEndpoint(program.opts<{ endpoint?: string }>().endpoint, context.env); |
| 22 | const client = context.createClient({ endpoint }); |
| 23 | |
| 24 | try { |
| 25 | const payload = await client.searchCodeSamples(query, options.language); |
| 26 | const output = options.json ? payload : formatCodeSearchResults(payload); |
| 27 | context.writeOut(ensureTrailingNewline(output)); |
| 28 | } finally { |
| 29 | await client.close(); |
| 30 | } |
| 31 | }); |
| 32 | } |
no test coverage detected