lookup

tcmts.cli.help.lookup · #ofkfe6ci · term · runs anywhere

A command's route, or one of its subcommands' (["data", "migrate"]), with its help: as help shows it.

import { helps, routes } from "#codebase/tcmts/cli/commands";
import { childrenOf, shape, withHelp } from "#codebase/tcmts/cli/help";
import type { RouteShape } from "#codebase/tcmts/cli/help";

export function lookup(path: string[]): RouteShape {
  let r = withHelp(
    shape(routes()[path[0] as keyof ReturnType<typeof routes>]()),
    helps()[path[0]!],
  );
  for (const seg of path.slice(1)) r = childrenOf(r).find((c) => c.name === seg) ?? r;
  return r;
}

uses

used by