Support equals-style short -o boolean parsing
Co-authored-by: Theo Browne <[email protected]>
This commit is contained in:
1 parent
ffe58dbb90
commit
3c222b17b7
2 files changed
+32
-1
No files matched your search
@@ -92,6 +92,14 @@ describe("parseCliOptions", () => {
|
||||
expect(options.noOpen).toBe(false);
|
||||
});
|
||||
|
||||
it("supports equals-style -o boolean values", () => {
|
||||
const enabled = parseCliOptions(["-o=true"], { T3_NO_OPEN: "true" }, "/workspace");
|
||||
expect(enabled.noOpen).toBe(false);
|
||||
|
||||
const disabled = parseCliOptions(["-o=0"], { T3_NO_OPEN: "false" }, "/workspace");
|
||||
expect(disabled.noOpen).toBe(true);
|
||||
});
|
||||
|
||||
it("supports explicit equals-style --open boolean overrides", () => {
|
||||
const options = parseCliOptions(
|
||||
["--open=false"],
|
||||
@@ -162,6 +170,12 @@ describe("parseCliOptions", () => {
|
||||
);
|
||||
});
|
||||
|
||||
it("throws for invalid equals-style -o values", () => {
|
||||
expect(() => parseCliOptions(["-o=maybe"], {}, "/workspace")).toThrow(
|
||||
"Invalid value for -o",
|
||||
);
|
||||
});
|
||||
|
||||
it("throws for empty equals-style --open values", () => {
|
||||
expect(() => parseCliOptions(["--open="], {}, "/workspace")).toThrow(
|
||||
"Invalid value for --open",
|
||||
@@ -468,6 +482,12 @@ describe("parseCliOptions", () => {
|
||||
);
|
||||
});
|
||||
|
||||
it("treats -o=bool after --backend-port as missing value", () => {
|
||||
expect(() => parseCliOptions(["--backend-port", "-o=true"], {}, "/workspace")).toThrow(
|
||||
"Missing value for --backend-port",
|
||||
);
|
||||
});
|
||||
|
||||
it("treats equals-style flag tokens after --backend-port as missing values", () => {
|
||||
expect(() =>
|
||||
parseCliOptions(["--backend-port", "--web-port=7000"], {}, "/workspace"),
|
||||
@@ -645,6 +665,12 @@ describe("parseCliOptions", () => {
|
||||
);
|
||||
});
|
||||
|
||||
it("treats -o=bool after --cwd as missing value", () => {
|
||||
expect(() => parseCliOptions(["--cwd", "-o=false"], {}, "/workspace")).toThrow(
|
||||
"Missing value for --cwd",
|
||||
);
|
||||
});
|
||||
|
||||
it("treats end-of-options marker after --cwd as missing value", () => {
|
||||
expect(() => parseCliOptions(["--cwd", "--"], {}, "/workspace")).toThrow(
|
||||
"Missing value for --cwd",
|
||||
|
||||
+6
-1
@@ -116,7 +116,7 @@ function isKnownFlagToken(value: string): boolean {
|
||||
}
|
||||
|
||||
for (const flag of KNOWN_CLI_FLAGS) {
|
||||
if (!flag.startsWith("--") || flag === "--") {
|
||||
if (flag === "--") {
|
||||
continue;
|
||||
}
|
||||
if (value.startsWith(`${flag}=`)) {
|
||||
@@ -235,6 +235,11 @@ export function parseCliOptions(
|
||||
continue;
|
||||
}
|
||||
|
||||
if (arg.startsWith("-o=")) {
|
||||
noOpen = !parseBooleanCliValue(arg.split("=")[1] ?? "", "-o");
|
||||
continue;
|
||||
}
|
||||
|
||||
if (arg.startsWith("--open=")) {
|
||||
noOpen = !parseBooleanCliValue(arg.split("=")[1] ?? "", "--open");
|
||||
continue;
|
||||
|
||||
Reference in new issue
Block a user