Skip to content

Commit 311399c

Browse files
committed
refactor: use Commander.js for top-level CLI routing
- Replace manual argv parsing with proper Commander.js subcommands - Add --version flag with proper version info - Subcommands (run, server) now properly routed via executableFile - Default action launches desktop app when no subcommand given - Update docs to reflect --version flag instead of subcommand
1 parent 44d5183 commit 311399c

File tree

3 files changed

+21
-23
lines changed

3 files changed

+21
-23
lines changed

docs/cli.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,11 +87,11 @@ Options:
8787
- `--auth-token <token>` - Optional bearer token for authentication
8888
- `--add-project <path>` - Add and open project at the specified path
8989

90-
## `mux version`
90+
## `mux --version`
9191

9292
Print the version and git commit:
9393

9494
```bash
95-
mux version
96-
# mux v0.8.4 (abc123)
95+
mux --version
96+
# v0.8.4 (abc123)
9797
```

src/cli/index.ts

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,22 @@
11
#!/usr/bin/env node
2+
import { Command } from "commander";
3+
import { VERSION } from "../version";
24

3-
const subcommand = process.argv.length > 2 ? process.argv[2] : null;
5+
const program = new Command();
46

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 === "run") {
11-
// Remove 'run' from args since run.ts uses Commander which handles its own parsing
12-
process.argv.splice(2, 1);
13-
// eslint-disable-next-line @typescript-eslint/no-require-imports
14-
require("./run");
15-
} else if (subcommand === "version") {
16-
// eslint-disable-next-line @typescript-eslint/no-require-imports
17-
const { VERSION } = require("../version") as {
18-
VERSION: { git_describe: string; git_commit: string };
19-
};
20-
console.log(`mux ${VERSION.git_describe} (${VERSION.git_commit})`);
21-
} else {
7+
program
8+
.name("mux")
9+
.description("Mux - AI agent orchestration")
10+
.version(`${VERSION.git_describe} (${VERSION.git_commit})`, "-v, --version");
11+
12+
program
13+
.command("run", "Run a one-off agent session", { executableFile: "./run" })
14+
.command("server", "Start the HTTP/WebSocket ORPC server", { executableFile: "./server" });
15+
16+
// Default to desktop app when no subcommand given
17+
program.action(() => {
2218
// eslint-disable-next-line @typescript-eslint/no-require-imports
2319
require("../desktop/main");
24-
}
20+
});
21+
22+
program.parse();

src/cli/server.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import type { ORPCContext } from "@/node/orpc/context";
1313

1414
const program = new Command();
1515
program
16-
.name("mux-server")
16+
.name("mux server")
1717
.description("HTTP/WebSocket ORPC server for mux")
1818
.option("-h, --host <host>", "bind to specific host", "localhost")
1919
.option("-p, --port <port>", "bind to specific port", "3000")

0 commit comments

Comments
 (0)