routeOf
What parsing reads of a command, or of one of its subcommands (["data", "migrate"]): its route, without its
help. Help reads lookup.
import { routes } from "#codebase/tcmts/cli/commands"; import { childrenOf, shape } from "#codebase/tcmts/cli/help"; import type { RouteShape } from "#codebase/tcmts/cli/help"; export function routeOf(path: string[]): RouteShape { let r = shape(routes()[path[0] as keyof ReturnType<typeof routes>]()); for (const seg of path.slice(1)) r = childrenOf(r).find((c) => c.name === seg) ?? r; return r; }