Open History to see the last commit
1import * as NodeRuntime from "@effect/platform-node/NodeRuntime";
2import * as NodeServices from "@effect/platform-node/NodeServices";
3import * as Effect from "effect/Effect";
4import * as Layer from "effect/Layer";
5import { Argument, Command } from "effect/unstable/cli";
6import * as CliError from "effect/unstable/cli/CliError";
7
8import * as NetService from "@t3tools/shared/Net";
9import packageJson from "../package.json" with { type: "json" };
10import { authCommand } from "./cli/auth.ts";
11import { connectCommand } from "./cli/connect.ts";
12import { pairCommand } from "./cli/pair.ts";
13import { hasCloudPublicConfig } from "./cloud/publicConfig.ts";
14import { sharedServerCommandFlags } from "./cli/config.ts";
15import { projectCommand } from "./cli/project.ts";
16import { runServerCommand, serveCommand, startCommand } from "./cli/server.ts";
17import { serviceCommand } from "./cli/service.ts";
18
19const CliRuntimeLayer = Layer.mergeAll(NodeServices.layer, NetService.layer);
20
21const connectPublicConfigMissingMessage =
22 "T3 Connect commands are unavailable: this build is missing T3 Connect public configuration.";
23
24class ConnectPublicConfigMissingError extends CliError.UserError {
25 override get message() {
26 return connectPublicConfigMissingMessage;
27 }
28}
29
30const connectUnavailableCommand = Command.make("connect", {
31 command: Argument.string("command").pipe(Argument.variadic),
32}).pipe(
33 Command.withDescription("T3 Connect is unavailable in builds without public configuration."),
34 Command.withHidden,
35 Command.withHandler(() =>
36 Effect.fail(
37 new CliError.ShowHelp({
38 commandPath: ["t3", "connect"],
39 errors: [new ConnectPublicConfigMissingError({ cause: connectPublicConfigMissingMessage })],
40 }),
41 ),
42 ),
43);
44
45export const makeCli = ({ cloudEnabled = hasCloudPublicConfig } = {}) =>
46 Command.make("t3", { ...sharedServerCommandFlags }).pipe(
47 Command.withDescription("Run the T3 Code server."),
48 Command.withHandler((flags) => runServerCommand(flags)),
49 Command.withSubcommands([
50 startCommand,
51 serveCommand,
52 pairCommand,
53 authCommand,
54 projectCommand,
55 serviceCommand,
56 cloudEnabled ? connectCommand : connectUnavailableCommand,
57 ]),
58 );
59
60export const cli = makeCli();
61
62if (import.meta.main) {
63 Command.run(cli, { version: packageJson.version }).pipe(
64 Effect.scoped,
65 Effect.provide(CliRuntimeLayer),
66 NodeRuntime.runMain,
67 );
68}