Skip to content

Commit 7535578

Browse files
committed
refactor: migrate CLI to commander for structured argument parsing
Replace manual argv parsing with commander.js to provide proper subcommand handling, automatic help generation, and conventional -v/--version flags. Adds trpc-cli as a dependency (likely for future oRPC CLI tooling).
1 parent 35ad55b commit 7535578

File tree

3 files changed

+38
-14
lines changed

3 files changed

+38
-14
lines changed

bun.lock

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
"ai": "^5.0.101",
3131
"ai-tokenizer": "^1.0.4",
3232
"chalk": "^5.6.2",
33+
"commander": "^14.0.2",
3334
"cors": "^2.8.5",
3435
"crc-32": "^1.2.2",
3536
"diff": "^8.0.2",
@@ -51,6 +52,7 @@
5152
"shescape": "^2.1.6",
5253
"source-map-support": "^0.5.21",
5354
"streamdown": "^1.4.0",
55+
"trpc-cli": "^0.12.1",
5456
"turndown": "^7.2.2",
5557
"undici": "^7.16.0",
5658
"write-file-atomic": "^6.0.0",
@@ -3401,6 +3403,8 @@
34013403

34023404
"trough": ["trough@2.2.0", "", {}, "sha512-tmMpK00BjZiUyVyvrBK7knerNgmgvcV/KLVyuma/SC+TQN167GrMRciANTz09+k3zW8L8t60jWO1GpfkZdjTaw=="],
34033405

3406+
"trpc-cli": ["trpc-cli@0.12.1", "", { "dependencies": { "commander": "^14.0.0" }, "peerDependencies": { "@orpc/server": "^1.0.0", "@trpc/server": "^10.45.2 || ^11.0.1", "@valibot/to-json-schema": "^1.1.0", "effect": "^3.14.2 || ^4.0.0", "valibot": "^1.1.0", "zod": "^3.24.0 || ^4.0.0" }, "optionalPeers": ["@orpc/server", "@trpc/server", "@valibot/to-json-schema", "effect", "valibot", "zod"], "bin": { "trpc-cli": "dist/bin.js" } }, "sha512-/D/mIQf3tUrS7ZKJZ1gmSPJn2psAABJfkC5Eevm55SZ4s6KwANOUNlwhAGXN9HT4VSJVfoF2jettevE9vHPQlg=="],
3407+
34043408
"truncate-utf8-bytes": ["truncate-utf8-bytes@1.0.2", "", { "dependencies": { "utf8-byte-length": "^1.0.1" } }, "sha512-95Pu1QXQvruGEhv62XCMO3Mm90GscOCClvrIUwCM0PYOXK3kaF3l3sIHxx71ThJfcbM2O5Au6SO3AWCSEfW4mQ=="],
34053409

34063410
"ts-api-utils": ["ts-api-utils@2.1.0", "", { "peerDependencies": { "typescript": ">=4.8.4" } }, "sha512-CUgTZL1irw8u29bzrOD/nH85jqyc74D6SshFgujOIA7osm2Rz7dYH77agkx7H4FBNxDq7Cjf+IjaX/8zwFW+ZQ=="],

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@
7171
"ai": "^5.0.101",
7272
"ai-tokenizer": "^1.0.4",
7373
"chalk": "^5.6.2",
74+
"commander": "^14.0.2",
7475
"cors": "^2.8.5",
7576
"crc-32": "^1.2.2",
7677
"diff": "^8.0.2",
@@ -92,6 +93,7 @@
9293
"shescape": "^2.1.6",
9394
"source-map-support": "^0.5.21",
9495
"streamdown": "^1.4.0",
96+
"trpc-cli": "^0.12.1",
9597
"turndown": "^7.2.2",
9698
"undici": "^7.16.0",
9799
"write-file-atomic": "^6.0.0",

src/cli/index.ts

Lines changed: 32 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,37 @@
11
#!/usr/bin/env node
22

3-
const subcommand = process.argv.length > 2 ? process.argv[2] : null;
3+
import { Command } from "commander";
4+
import { VERSION } from "../version";
45

5-
if (subcommand === "server") {
6-
// Remove 'server' from args since main-server doesn't expect it as a positional argument.
7-
process.argv.splice(2, 1);
8-
// eslint-disable-next-line @typescript-eslint/no-require-imports
9-
require("./server");
10-
} else if (subcommand === "version") {
11-
// eslint-disable-next-line @typescript-eslint/no-require-imports
12-
const { VERSION } = require("../version") as {
13-
VERSION: { git_describe: string; git_commit: string };
14-
};
15-
console.log(`mux ${VERSION.git_describe} (${VERSION.git_commit})`);
16-
} else {
6+
const program = new Command();
7+
8+
program
9+
.name("mux")
10+
.description("mux - coder multiplexer")
11+
.version(`mux ${VERSION.git_describe} (${VERSION.git_commit})`, "-v, --version");
12+
13+
program
14+
.command("server")
15+
.description("Start the HTTP/WebSocket oRPC server")
16+
.allowUnknownOption() // server.ts handles its own options via commander
17+
.action(() => {
18+
// Remove 'server' from args since server.ts has its own commander instance
19+
process.argv.splice(2, 1);
20+
// eslint-disable-next-line @typescript-eslint/no-require-imports
21+
require("./server");
22+
});
23+
24+
program
25+
.command("version")
26+
.description("Show version information")
27+
.action(() => {
28+
console.log(`mux ${VERSION.git_describe} (${VERSION.git_commit})`);
29+
});
30+
31+
// Default action: launch desktop app when no subcommand given
32+
program.action(() => {
1733
// eslint-disable-next-line @typescript-eslint/no-require-imports
1834
require("../desktop/main");
19-
}
35+
});
36+
37+
program.parse();

0 commit comments

Comments
 (0)