| 9 | import { emitJson, emitLine, pad, truncate } from '../format.js' |
| 10 | |
| 11 | export async function cmdSearch(vault: string, args: ParsedArgs): Promise<void> { |
| 12 | const query = getString(args, 'query') ?? args.positionals.join(' ') |
| 13 | if (!query.trim()) throw new Error('zn search requires a query.') |
| 14 | const limit = getNumber(args, 'limit') ?? 50 |
| 15 | const matches = await searchText(vault, query.trim(), limit) |
| 16 | if (getBool(args, 'json')) { |
| 17 | emitJson(matches) |
| 18 | return |
| 19 | } |
| 20 | if (matches.length === 0) { |
| 21 | emitLine(`No matches for "${query}".`) |
| 22 | return |
| 23 | } |
| 24 | for (const m of matches) { |
| 25 | emitLine(`${pad(`${m.path}:${m.lineNumber}`, 48)} ${truncate(m.lineText, 100)}`) |
| 26 | } |
| 27 | } |
| 28 | |
| 29 | export async function cmdSearchTitle(vault: string, args: ParsedArgs): Promise<void> { |
| 30 | const query = getString(args, 'query') ?? args.positionals.join(' ') |