Support positional cwd argument for t3 CLI
Co-authored-by: Theo Browne <[email protected]>
This commit is contained in:
1 parent
f153feb623
commit
ed2ef7d178
3 files changed
+23
No files matched your search
@@ -26,6 +26,7 @@ CLI flags:
|
||||
- `--backend-port <port>` — set WebSocket runtime port.
|
||||
- `--web-port <port>` — set web UI port.
|
||||
- `--cwd <path>` — choose launch project directory (defaults to current directory).
|
||||
- `<path>` — shorthand positional argument equivalent to `--cwd <path>`.
|
||||
- `--version` — print CLI version.
|
||||
- `--help` — print CLI usage.
|
||||
|
||||
|
||||
@@ -47,6 +47,17 @@ describe("parseCliOptions", () => {
|
||||
expect(options.webPortLocked).toBe(true);
|
||||
});
|
||||
|
||||
it("accepts a positional cwd argument", () => {
|
||||
const options = parseCliOptions(["apps/renderer"], {}, "/workspace");
|
||||
expect(options.launchCwd).toBe(path.resolve("apps/renderer"));
|
||||
});
|
||||
|
||||
it("rejects multiple positional cwd arguments", () => {
|
||||
expect(() => parseCliOptions(["apps/renderer", "apps/t3"], {}, "/workspace")).toThrow(
|
||||
"Unexpected positional argument: apps/t3",
|
||||
);
|
||||
});
|
||||
|
||||
it("keeps ports unlocked when using defaults", () => {
|
||||
const options = parseCliOptions([], {}, "/workspace");
|
||||
expect(options.backendPortLocked).toBe(false);
|
||||
|
||||
@@ -88,6 +88,7 @@ export function parseCliOptions(
|
||||
let backendPortLocked = Boolean(env.T3_BACKEND_PORT);
|
||||
let webPortLocked = Boolean(env.T3_WEB_PORT);
|
||||
let launchCwd = cwd;
|
||||
let usedPositionalCwd = false;
|
||||
let noOpen = env.T3_NO_OPEN === "1";
|
||||
let showHelp = false;
|
||||
let showVersion = false;
|
||||
@@ -151,6 +152,15 @@ export function parseCliOptions(
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!arg.startsWith("-")) {
|
||||
if (usedPositionalCwd) {
|
||||
throw new Error(`Unexpected positional argument: ${arg}`);
|
||||
}
|
||||
launchCwd = path.resolve(arg);
|
||||
usedPositionalCwd = true;
|
||||
continue;
|
||||
}
|
||||
|
||||
throw new Error(`Unknown argument: ${arg}`);
|
||||
}
|
||||
|
||||
@@ -176,6 +186,7 @@ function printHelp(): void {
|
||||
" --backend-port <port> Override WebSocket API port (default: 4317)",
|
||||
" --web-port <port> Override web UI port (default: 4318)",
|
||||
" --cwd <path> Launch project directory (default: current directory)",
|
||||
" [path] Positional shorthand for --cwd <path>",
|
||||
" -v, --version Print CLI version",
|
||||
" -h, --help Show this help message",
|
||||
"",
|
||||
|
||||
Reference in new issue
Block a user