findByType

tcmts.cli.main.findByType · #vj5e4fed · term · runs on the server

uses tcmts.cli.search.searchByType, which uses node:path

tcm find ':<type>': terms whose type has that shape (see search.ts).

import type { Codebase } from "#codebase/tcmts/cli/codebase";
import { cutSignature, SIGNATURE_WIDTH } from "#codebase/tcmts/cli/main";
import { searchByType } from "#codebase/tcmts/cli/search";
import { bold, dim, yellow } from "#codebase/tcmts/cli/style";
import { shortHash } from "#codebase/tcmts/core/hash";

export function findByType(cb: Codebase, text: string) {
  const r = searchByType(cb, text);
  if (r.variables.length) console.log(dim(`type variables: ${r.variables.join(", ")}`));
  if (!r.hits.length) return console.log(dim("no matches"));
  for (const h of r.hits) console.log(`${bold(h.path)}  ${dim(shortHash(h.hash))}  ${dim(cutSignature(h.signature, Math.max(40, SIGNATURE_WIDTH - h.path.length)))}${h.cost ? `  ${yellow(h.notes.join(", "))}` : ""}`);
}

uses

used by