execute

tcmts.cli.main.execute · #idba2jyz · term · runs on the server

uses tcmts.cli.help.usageError, which uses tcmts.cli.help.usageOf, which uses tcmts.cli.style.bold, which uses node:util

A parsed command line, if it asks to run the command: help and the version are printed instead, and a line the command doesn't accept is a usage error saying why.

import { helpText, usageError } from "#codebase/tcmts/cli/help";
import { Printed } from "#codebase/tcmts/cli/main";
import { dim } from "#codebase/tcmts/cli/style";
import { UsageError } from "#codebase/tcmts/cli/ui";
import { IR_VERSION } from "#codebase/tcmts/core/hash";
import { TS_VERSION } from "#codebase/tcmts/core/program";

export function execute<R extends { ok: boolean }>(
  cmd: string | undefined,
  r: R,
): Extract<R, { method: "execute" }> {
  const x = r as unknown as {
    ok: boolean;
    method?: string;
    path?: string[];
    code: string;
    issues?: { message: string; path?: unknown[] }[];
  };
  const where = [...(cmd ? [cmd] : []), ...(x.path ?? [])];
  if (!x.ok) throw new UsageError(usageError(where, x));
  if (x.method === "help") throw new Printed(helpText(where));
  if (x.method === "version")
    throw new Printed(`tcm ${dim(`(hash format v${IR_VERSION}, TypeScript ${TS_VERSION})`)}`);
  return r as never;
}

uses

used by