MCPcopy Create free account
hub / github.com/ZenNotes/zennotes / cmdSearch

Function cmdSearch

apps/desktop/src/cli/commands/search.ts:11–27  ·  view source on GitHub ↗
(vault: string, args: ParsedArgs)

Source from the content-addressed store, hash-verified

9import { emitJson, emitLine, pad, truncate } from '../format.js'
10
11export 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
29export async function cmdSearchTitle(vault: string, args: ParsedArgs): Promise<void> {
30 const query = getString(args, 'query') ?? args.positionals.join(' ')

Callers

nothing calls this directly

Calls 8

padFunction · 0.90
getStringFunction · 0.85
getNumberFunction · 0.85
searchTextFunction · 0.85
getBoolFunction · 0.85
emitJsonFunction · 0.85
emitLineFunction · 0.85
truncateFunction · 0.85

Tested by

no test coverage detected