Treat equals-style flags as missing arg values
Co-authored-by: Theo Browne <[email protected]>
This commit is contained in:
1 parent
86e541a697
commit
7a704b2eae
2 files changed
+36
-1
No files matched your search
@@ -378,6 +378,12 @@ describe("parseCliOptions", () => {
|
||||
);
|
||||
});
|
||||
|
||||
it("treats equals-style flag tokens after --backend-port as missing values", () => {
|
||||
expect(() =>
|
||||
parseCliOptions(["--backend-port", "--web-port=7000"], {}, "/workspace"),
|
||||
).toThrow("Missing value for --backend-port");
|
||||
});
|
||||
|
||||
it("treats end-of-options marker after --backend-port as missing value", () => {
|
||||
expect(() => parseCliOptions(["--backend-port", "--"], {}, "/workspace")).toThrow(
|
||||
"Missing value for --backend-port",
|
||||
@@ -402,6 +408,12 @@ describe("parseCliOptions", () => {
|
||||
);
|
||||
});
|
||||
|
||||
it("treats equals-style flag tokens after --web-port as missing values", () => {
|
||||
expect(() =>
|
||||
parseCliOptions(["--web-port", "--backend-port=7000"], {}, "/workspace"),
|
||||
).toThrow("Missing value for --web-port");
|
||||
});
|
||||
|
||||
it("treats end-of-options marker after --web-port as missing value", () => {
|
||||
expect(() => parseCliOptions(["--web-port", "--"], {}, "/workspace")).toThrow(
|
||||
"Missing value for --web-port",
|
||||
@@ -501,6 +513,12 @@ describe("parseCliOptions", () => {
|
||||
);
|
||||
});
|
||||
|
||||
it("treats equals-style flag tokens after --cwd as missing values", () => {
|
||||
expect(() => parseCliOptions(["--cwd", "--open=false"], {}, "/workspace")).toThrow(
|
||||
"Missing value for --cwd",
|
||||
);
|
||||
});
|
||||
|
||||
it("treats --open after --cwd as missing value", () => {
|
||||
expect(() => parseCliOptions(["--cwd", "--open"], {}, "/workspace")).toThrow(
|
||||
"Missing value for --cwd",
|
||||
|
||||
+18
-1
@@ -108,6 +108,23 @@ const KNOWN_CLI_FLAGS = new Set([
|
||||
"--",
|
||||
]);
|
||||
|
||||
function isKnownFlagToken(value: string): boolean {
|
||||
if (KNOWN_CLI_FLAGS.has(value)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
for (const flag of KNOWN_CLI_FLAGS) {
|
||||
if (!flag.startsWith("--") || flag === "--") {
|
||||
continue;
|
||||
}
|
||||
if (value.startsWith(`${flag}=`)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
function readArgValue(
|
||||
args: string[],
|
||||
index: number,
|
||||
@@ -125,7 +142,7 @@ function readArgValue(
|
||||
if (!options?.allowDashPrefixed && dashPrefixed) {
|
||||
throw new Error(`Missing value for ${key}.`);
|
||||
}
|
||||
if (options?.allowDashPrefixed && dashPrefixed && KNOWN_CLI_FLAGS.has(value)) {
|
||||
if (options?.allowDashPrefixed && dashPrefixed && isKnownFlagToken(value)) {
|
||||
throw new Error(`Missing value for ${key}.`);
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user