Parse config file in entry

This way setting --data-dir and --extension-dir in the config file
will work for --install--extension and whatnot.
This commit is contained in:
Anmol Sethi 2020-05-28 03:31:11 -04:00
parent 7ab47b3d83
commit 2c2a6498af
No known key found for this signature in database
GPG Key ID: 8CEF1878FF10ADEB
1 changed files with 9 additions and 10 deletions

View File

@ -31,11 +31,7 @@ try {
const version = pkg.version || "development" const version = pkg.version || "development"
const commit = pkg.commit || "development" const commit = pkg.commit || "development"
const main = async (cliArgs: Args): Promise<void> => { const main = async (args: Args, cliArgs: Args, configArgs: Args): Promise<void> => {
const configArgs = await readConfigFile(cliArgs.config)
// This prioritizes the flags set in args over the ones in the config file.
let args = Object.assign(configArgs, cliArgs)
if (!args.auth) { if (!args.auth) {
args = { args = {
...args, ...args,
@ -145,18 +141,21 @@ function trimLDLibraryPath(): void {
async function entry(): Promise<void> { async function entry(): Promise<void> {
trimLDLibraryPath() trimLDLibraryPath()
const tryParse = async (): Promise<Args> => { const tryParse = async (): Promise<[Args, Args, Args]> => {
try { try {
let args = parse(process.argv.slice(2)) const cliArgs = parse(process.argv.slice(2))
const configArgs = await readConfigFile(cliArgs.config)
// This prioritizes the flags set in args over the ones in the config file.
let args = Object.assign(configArgs, cliArgs)
args = await setDefaults(args) args = await setDefaults(args)
return args return [args, cliArgs, configArgs]
} catch (error) { } catch (error) {
console.error(error.message) console.error(error.message)
process.exit(1) process.exit(1)
} }
} }
const args = await tryParse() const [args, cliArgs, configArgs] = await tryParse()
if (args.help) { if (args.help) {
console.log("code-server", version, commit) console.log("code-server", version, commit)
console.log("") console.log("")
@ -200,7 +199,7 @@ async function entry(): Promise<void> {
}) })
vscode.on("exit", (code) => process.exit(code || 0)) vscode.on("exit", (code) => process.exit(code || 0))
} else { } else {
wrap(() => main(args)) wrap(() => main(args, cliArgs, configArgs))
} }
} }