mirror of
https://github.com/coder/code-server.git
synced 2025-09-18 18:57:50 +08:00
@ -713,12 +713,16 @@ export function parseConfigFile(configFile: string, configPath: string): ConfigA
|
|||||||
|
|
||||||
// We convert the config file into a set of flags.
|
// We convert the config file into a set of flags.
|
||||||
// This is a temporary measure until we add a proper CLI library.
|
// This is a temporary measure until we add a proper CLI library.
|
||||||
const configFileArgv = Object.entries(config).map(([optName, opt]) => {
|
const configFileArgv = Object.entries(config)
|
||||||
if (opt === true) {
|
.map(([optName, opt]) => {
|
||||||
return `--${optName}`
|
if (opt === true) {
|
||||||
}
|
return `--${optName}`
|
||||||
return `--${optName}=${opt}`
|
} else if (Array.isArray(opt)) {
|
||||||
})
|
return opt.map((o) => `--${optName}=${o}`)
|
||||||
|
}
|
||||||
|
return `--${optName}=${opt}`
|
||||||
|
})
|
||||||
|
.flat()
|
||||||
const args = parse(configFileArgv, {
|
const args = parse(configFileArgv, {
|
||||||
configFile: configPath,
|
configFile: configPath,
|
||||||
})
|
})
|
||||||
|
@ -6,6 +6,7 @@ import {
|
|||||||
bindAddrFromArgs,
|
bindAddrFromArgs,
|
||||||
defaultConfigFile,
|
defaultConfigFile,
|
||||||
parse,
|
parse,
|
||||||
|
parseConfigFile,
|
||||||
setDefaults,
|
setDefaults,
|
||||||
shouldOpenInExistingInstance,
|
shouldOpenInExistingInstance,
|
||||||
toCodeArgs,
|
toCodeArgs,
|
||||||
@ -287,12 +288,17 @@ describe("parser", () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
it("should support repeatable flags", async () => {
|
it("should support repeatable flags", async () => {
|
||||||
|
expect(() => parse(["--proxy-domain", ""])).toThrowError(/--proxy-domain requires a value/)
|
||||||
expect(parse(["--proxy-domain", "*.coder.com"])).toEqual({
|
expect(parse(["--proxy-domain", "*.coder.com"])).toEqual({
|
||||||
"proxy-domain": ["*.coder.com"],
|
"proxy-domain": ["*.coder.com"],
|
||||||
})
|
})
|
||||||
expect(parse(["--proxy-domain", "*.coder.com", "--proxy-domain", "test.com"])).toEqual({
|
expect(parse(["--proxy-domain", "*.coder.com", "--proxy-domain", "test.com"])).toEqual({
|
||||||
"proxy-domain": ["*.coder.com", "test.com"],
|
"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 () => {
|
it("should enforce cert-key with cert value or otherwise generate one", async () => {
|
||||||
@ -490,6 +496,20 @@ describe("parser", () => {
|
|||||||
}),
|
}),
|
||||||
).toThrowError(expectedErrMsg)
|
).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 () => {
|
it("should ignore optional strings set to false", async () => {
|
||||||
expect(parse(["--cert=false"])).toEqual({})
|
expect(parse(["--cert=false"])).toEqual({})
|
||||||
})
|
})
|
||||||
|
Reference in New Issue
Block a user