Fix repeatable flags in config

Fixes #6149.
This commit is contained in:
Asher
2025-05-05 12:46:24 -08:00
committed by Asher
parent 0c72b20fa7
commit c8257a3074
2 changed files with 30 additions and 6 deletions

View File

@ -6,6 +6,7 @@ import {
bindAddrFromArgs,
defaultConfigFile,
parse,
parseConfigFile,
setDefaults,
shouldOpenInExistingInstance,
toCodeArgs,
@ -287,12 +288,17 @@ describe("parser", () => {
})
it("should support repeatable flags", async () => {
expect(() => parse(["--proxy-domain", ""])).toThrowError(/--proxy-domain requires a value/)
expect(parse(["--proxy-domain", "*.coder.com"])).toEqual({
"proxy-domain": ["*.coder.com"],
})
expect(parse(["--proxy-domain", "*.coder.com", "--proxy-domain", "test.com"])).toEqual({
"proxy-domain": ["*.coder.com", "test.com"],
})
// Commas are literal, at the moment.
expect(parse(["--proxy-domain", "*.coder.com,test.com"])).toEqual({
"proxy-domain": ["*.coder.com,test.com"],
})
})
it("should enforce cert-key with cert value or otherwise generate one", async () => {
@ -490,6 +496,20 @@ describe("parser", () => {
}),
).toThrowError(expectedErrMsg)
})
it("should fail to parse invalid config", () => {
expect(() => parseConfigFile("test", "/fake-config-path")).toThrowError("invalid config: test")
})
it("should parse repeatable options", () => {
const configContents = `
install-extension:
- extension.number1
- extension.number2
`
expect(parseConfigFile(configContents, "/fake-config-path")).toEqual({
config: "/fake-config-path",
"install-extension": ["extension.number1", "extension.number2"],
})
})
it("should ignore optional strings set to false", async () => {
expect(parse(["--cert=false"])).toEqual({})
})