Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit c8257a3

Browse files
Fix repeatable flags in config
Fixes #6149.
1 parent 0c72b20 commit c8257a3

File tree

2 files changed

+30
-6
lines changed

2 files changed

+30
-6
lines changed

‎src/node/cli.ts‎

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -713,12 +713,16 @@ export function parseConfigFile(configFile: string, configPath: string): ConfigA
713713

714714
// We convert the config file into a set of flags.
715715
// This is a temporary measure until we add a proper CLI library.
716-
const configFileArgv = Object.entries(config).map(([optName, opt]) => {
717-
if (opt === true) {
718-
return `--${optName}`
719-
}
720-
return `--${optName}=${opt}`
721-
})
716+
const configFileArgv = Object.entries(config)
717+
.map(([optName, opt]) => {
718+
if (opt === true) {
719+
return `--${optName}`
720+
} else if (Array.isArray(opt)) {
721+
return opt.map((o) => `--${optName}=${o}`)
722+
}
723+
return `--${optName}=${opt}`
724+
})
725+
.flat()
722726
const args = parse(configFileArgv, {
723727
configFile: configPath,
724728
})

‎test/unit/node/cli.test.ts‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
bindAddrFromArgs,
77
defaultConfigFile,
88
parse,
9+
parseConfigFile,
910
setDefaults,
1011
shouldOpenInExistingInstance,
1112
toCodeArgs,
@@ -287,12 +288,17 @@ describe("parser", () => {
287288
})
288289

289290
it("should support repeatable flags", async () => {
291+
expect(() => parse(["--proxy-domain", ""])).toThrowError(/--proxy-domainrequiresavalue/)
290292
expect(parse(["--proxy-domain", "*.coder.com"])).toEqual({
291293
"proxy-domain": ["*.coder.com"],
292294
})
293295
expect(parse(["--proxy-domain", "*.coder.com", "--proxy-domain", "test.com"])).toEqual({
294296
"proxy-domain": ["*.coder.com", "test.com"],
295297
})
298+
// Commas are literal, at the moment.
299+
expect(parse(["--proxy-domain", "*.coder.com,test.com"])).toEqual({
300+
"proxy-domain": ["*.coder.com,test.com"],
301+
})
296302
})
297303

298304
it("should enforce cert-key with cert value or otherwise generate one", async () => {
@@ -490,6 +496,20 @@ describe("parser", () => {
490496
}),
491497
).toThrowError(expectedErrMsg)
492498
})
499+
it("should fail to parse invalid config", () => {
500+
expect(() => parseConfigFile("test", "/fake-config-path")).toThrowError("invalid config: test")
501+
})
502+
it("should parse repeatable options", () => {
503+
const configContents = `
504+
install-extension:
505+
- extension.number1
506+
- extension.number2
507+
`
508+
expect(parseConfigFile(configContents, "/fake-config-path")).toEqual({
509+
config: "/fake-config-path",
510+
"install-extension": ["extension.number1", "extension.number2"],
511+
})
512+
})
493513
it("should ignore optional strings set to false", async () => {
494514
expect(parse(["--cert=false"])).toEqual({})
495515
})

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /