runCommand

tcmts.cli.main.runCommand · #4wzunmfh · term · runs on the server

uses process

Run a command as tcm does at a terminal, errors reported: its exit code (-1 for one that keeps running, like tcm watch). A bug's error (a TypeError, a RangeError) is thrown on, with its stack.

import { main } from "#codebase/tcmts/cli/main";
import { red } from "#codebase/tcmts/cli/style";
import { UsageError } from "#codebase/tcmts/cli/ui";

export async function runCommand(argv: string[]): Promise<number> {
  try {
    return await main(argv);
  } catch (e) {
    if (
      e instanceof UsageError ||
      (e instanceof Error && !(e instanceof TypeError) && !(e instanceof RangeError))
    ) {
      console.error(red(e.message));
      if (process.env.TCM_DEBUG) console.error(e.stack);
      return 1;
    }
    throw e;
  }
}

uses

used by