lookup
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
- tcmts.cli.commands.helps
- tcmts.cli.commands.routes
- tcmts.cli.help.RouteShape
- tcmts.cli.help.childrenOf
- tcmts.cli.help.shape
- tcmts.cli.help.withHelp