notFound

tcmts.cli.help.notFound · #fwxepp2z · term · runs anywhere

What to say for a name that isn't found, given the names there are: a namespace's (what it holds), or the names meant most likely (the same name in another namespace, or one spelled almost the same).

import { nearNames } from "#codebase/tcmts/cli/help";

export function notFound(paths: string[], target: string): string {
  if (target.startsWith("#"))
    return `'${target}' not found: no definition's hash starts with ${target.slice(1)}`;
  const inside = paths.filter((p) => p.startsWith(`${target}.`));
  if (inside.length) {
    const children = [...new Set(inside.map((p) => p.slice(target.length + 1).split(".")[0]!))];
    const listed =
      children.slice(0, 12).join(", ") +
      (children.length > 12 ? `, and ${children.length - 12} more` : "");
    return `'${target}' is a namespace, not a definition: it holds ${listed}; give one of their names (\`tcm ls ${target}\` lists them)`;
  }
  const near = nearNames(paths, target);
  return `'${target}' not found${near.length ? `; did you mean ${near.join(", ")}?` : ""}`;
}

uses

used by