diff --git a/src/node/cli.ts b/src/node/cli.ts index 2e24b32ce..a29ec591e 100644 --- a/src/node/cli.ts +++ b/src/node/cli.ts @@ -713,12 +713,16 @@ export function parseConfigFile(configFile: string, configPath: string): ConfigA // We convert the config file into a set of flags. // This is a temporary measure until we add a proper CLI library. - const configFileArgv = Object.entries(config).map(([optName, opt]) => { - if (opt === true) { - return `--${optName}` - } - return `--${optName}=${opt}` - }) + const configFileArgv = Object.entries(config) + .map(([optName, opt]) => { + if (opt === true) { + return `--${optName}` + } else if (Array.isArray(opt)) { + return opt.map((o) => `--${optName}=${o}`) + } + return `--${optName}=${opt}` + }) + .flat() const args = parse(configFileArgv, { configFile: configPath, }) diff --git a/test/unit/node/cli.test.ts b/test/unit/node/cli.test.ts index 552576fac..d62edb840 100644 --- a/test/unit/node/cli.test.ts +++ b/test/unit/node/cli.test.ts @@ -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({}) })