MCPcopy Index your code
hub / github.com/coder/code-server / parseConfigFile

Function parseConfigFile

src/node/cli.ts:754–785  ·  view source on GitHub ↗
(configFile: string, configPath: string)

Source from the content-addressed store, hash-verified

752 * configPath is used as the filename in error messages
753 */
754export function parseConfigFile(configFile: string, configPath: string): ConfigArgs {
755 if (!configFile) {
756 return { config: configPath }
757 }
758
759 const config = load(configFile, {
760 filename: configPath,
761 })
762 if (!config || typeof config === "string") {
763 throw new Error(`invalid config: ${config}`)
764 }
765
766 // We convert the config file into a set of flags.
767 // This is a temporary measure until we add a proper CLI library.
768 const configFileArgv = Object.entries(config)
769 .map(([optName, opt]) => {
770 if (opt === true) {
771 return `--${optName}`
772 } else if (Array.isArray(opt)) {
773 return opt.map((o) => `--${optName}=${o}`)
774 }
775 return `--${optName}=${opt}`
776 })
777 .flat()
778 const args = parse(configFileArgv, {
779 configFile: configPath,
780 })
781 return {
782 ...args,
783 config: configPath,
784 }
785}
786
787function parseBindAddr(bindAddr: string): Addr {
788 const u = new URL(`http://${bindAddr}`)

Callers 3

setupFunction · 0.90
cli.test.tsFile · 0.90
readConfigFileFunction · 0.85

Calls 1

parseFunction · 0.85

Tested by

no test coverage detected