mirror of
https://github.com/coder/code-server.git
synced 2025-07-25 10:53:24 +08:00
@ -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,
|
||||
})
|
||||
|
@ -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({})
|
||||
})
|
||||
|
Reference in New Issue
Block a user