Support -- end-of-options path parsing
Co-authored-by: Theo Browne <[email protected]>
This commit is contained in:
1 parent
a5b9eb61c9
commit
be21363654
2 files changed
+32
No files matched your search
@@ -145,6 +145,21 @@ describe("parseCliOptions", () => {
|
||||
);
|
||||
});
|
||||
|
||||
it("supports end-of-options marker for positional cwd values", () => {
|
||||
const options = parseCliOptions(["--", "-project"], {}, "/workspace");
|
||||
expect(options.launchCwd).toBe(path.resolve("/workspace", "-project"));
|
||||
});
|
||||
|
||||
it("throws when end-of-options marker has no positional value", () => {
|
||||
expect(() => parseCliOptions(["--"], {}, "/workspace")).toThrow("Missing value for [path]");
|
||||
});
|
||||
|
||||
it("throws when end-of-options marker has multiple positional values", () => {
|
||||
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);
|
||||
|
||||
@@ -131,6 +131,23 @@ export function parseCliOptions(
|
||||
const arg = argv[index];
|
||||
if (!arg) continue;
|
||||
|
||||
if (arg === "--") {
|
||||
const positionalArgs = argv.slice(index + 1);
|
||||
const [first, ...rest] = positionalArgs;
|
||||
if (!first) {
|
||||
throw new Error("Missing value for [path].");
|
||||
}
|
||||
if (usedPositionalCwd) {
|
||||
throw new Error(`Unexpected positional argument: ${first}`);
|
||||
}
|
||||
if (rest.length > 0) {
|
||||
throw new Error(`Unexpected positional argument: ${rest[0]}`);
|
||||
}
|
||||
launchCwd = parseExplicitPath(first, "[path]", parserCwd);
|
||||
usedPositionalCwd = true;
|
||||
break;
|
||||
}
|
||||
|
||||
if (arg === "--help" || arg === "-h") {
|
||||
showHelp = true;
|
||||
continue;
|
||||
|
||||
Reference in new issue
Block a user