find
uses tcmts.cli.style.dim, which uses node:util
tcm find <query>: the names with every word of query in their name, signature or doc (any case), those it's in
the name or signature of first; the docs are as this branch shows them (its text versions). A query starting with
: is a type ([findByType]).
import type { Codebase } from "#codebase/tcmts/cli/codebase"; import { cutSignature, findByType, SIGNATURE_WIDTH } from "#codebase/tcmts/cli/main"; import { bold, dim } from "#codebase/tcmts/cli/style"; import { shortHash } from "#codebase/tcmts/core/hash"; export function find(cb: Codebase, query: string) { if (query.trim().startsWith(":")) return findByType(cb, query.trim().slice(1)); const words = query.toLowerCase().split(/\s+/).filter(Boolean); const has = (...texts: string[]) => { const t = texts.join("\n").toLowerCase(); return words.every((w) => t.includes(w)); }; const docs = new Map(cb.store.documentedNames().map((d) => [`${d.path} ${d.hash}`, d.doc])); const named = cb.store.signedNames(true); const byName = named.filter((n) => has(n.path, n.signature)); const byDoc = named.filter((n) => { const doc = docs.get(`${n.path} ${n.hash}`); return doc !== undefined && !has(n.path, n.signature) && has(n.path, n.signature, doc); }); const hits = [...byName, ...byDoc]; if (!hits.length) return console.log(dim("no matches")); for (const n of hits) console.log( `${bold(n.path)} ${dim(shortHash(n.hash))} ${dim(cutSignature(n.signature, Math.max(40, SIGNATURE_WIDTH - n.path.length)))}`, ); }
uses
- tcmts.cli.codebase.Codebase
- tcmts.cli.main.SIGNATURE_WIDTH
- tcmts.cli.main.cutSignature
- tcmts.cli.main.findByType
- tcmts.cli.style.bold
- tcmts.cli.style.dim
- tcmts.core.hash.shortHash