usageOf
uses tcmts.cli.style.bold, which uses node:util
What a command takes, as its help says it: its usage line (its subcommands'), arguments, subcommands and options. Help shows it, and so does a usage error.
import { argLabel, childrenOf, described, lookup, optionLabel, paramsOf, rows } from "#codebase/tcmts/cli/help"; import { bold } from "#codebase/tcmts/cli/style"; export function usageOf(path: string[]): string[] { const r = lookup(path); const params = paramsOf(r); const args = params.filter((p) => p.cli.syntax!.type === "argument"); const options = params.filter((p) => p.cli.syntax!.type === "option"); const children = childrenOf(r); const usage = [ `tcm ${path.join(" ")}`, ...args.map(argLabel), ...(options.length ? ["[options]"] : []), ].join(" "); const out = [bold("Usage"), ` ${usage}`]; for (const c of children) out.push( ` tcm ${path.join(" ")} ${c.name}${ paramsOf(c).some((p) => p.cli.syntax!.type === "argument") ? " " + paramsOf(c) .filter((p) => p.cli.syntax!.type === "argument") .map(argLabel) .join(" ") : "" }`, ); if (args.length) out.push("", bold("Arguments"), ...rows(args.map((p) => [p.name, described(p)]))); if (children.length) out.push("", bold("Commands"), ...rows(children.map((c) => [c.name, c.description ?? ""]))); out.push( "", bold("Options"), ...rows([ ...options.map((p): [string, string] => [optionLabel(p), described(p)]), ["-h, --help", "show this help"], ]), ); return out; }
uses
- tcmts.cli.help.argLabel
- tcmts.cli.help.childrenOf
- tcmts.cli.help.described
- tcmts.cli.help.lookup
- tcmts.cli.help.optionLabel
- tcmts.cli.help.paramsOf
- tcmts.cli.help.rows
- tcmts.cli.style.bold