(config: Config, flags: GlobalFlags)
| 30 | 'mmx search query --q "latest news" --output json', |
| 31 | ], |
| 32 | async run(config: Config, flags: GlobalFlags) { |
| 33 | const query = (flags.q ?? flags.query ?? (flags._positional as string[]|undefined)?.[0]) as string | undefined; |
| 34 | |
| 35 | if (!query) { |
| 36 | throw new CLIError( |
| 37 | '--q is required.', |
| 38 | ExitCode.USAGE, |
| 39 | 'mmx search query --q "your search query"', |
| 40 | ); |
| 41 | } |
| 42 | |
| 43 | const format = detectOutputFormat(config.output); |
| 44 | |
| 45 | if (config.dryRun) { |
| 46 | console.log(formatOutput({ request: { q: query } }, format)); |
| 47 | return; |
| 48 | } |
| 49 | |
| 50 | const url = searchEndpoint(config.baseUrl); |
| 51 | const response = await requestJson<SearchResponse>(config, { |
| 52 | url, |
| 53 | method: 'POST', |
| 54 | body: { q: query }, |
| 55 | }); |
| 56 | |
| 57 | const results = response.organic || []; |
| 58 | |
| 59 | if (format !== 'text') { |
| 60 | console.log(formatOutput(response, format)); |
| 61 | return; |
| 62 | } |
| 63 | |
| 64 | if (config.quiet) { |
| 65 | for (const r of results) { |
| 66 | console.log(`${r.title}\t${r.link}`); |
| 67 | } |
| 68 | return; |
| 69 | } |
| 70 | |
| 71 | if (results.length === 0) { |
| 72 | console.log('No results found.'); |
| 73 | return; |
| 74 | } |
| 75 | |
| 76 | for (const r of results) { |
| 77 | console.log(`${r.title}`); |
| 78 | console.log(` ${r.link}`); |
| 79 | if (r.snippet) console.log(` ${r.snippet}`); |
| 80 | if (r.date) console.log(` ${r.date}`); |
| 81 | console.log(''); |
| 82 | } |
| 83 | }, |
| 84 | }); |
nothing calls this directly
no test coverage detected