Archived
1
0

Allow user-data-dir and extension-dir in config.yaml

Closes #1676
This commit is contained in:
Anmol Sethi
2020-05-19 00:39:57 -04:00
parent aa87270148
commit 8053ec6872
3 changed files with 58 additions and 52 deletions

View File

@ -152,12 +152,12 @@ export const optionDescriptions = (): string[] => {
)
}
export const parse = async (
export const parse = (
argv: string[],
opts?: {
configFile: string
},
): Promise<Args> => {
): Args => {
const error = (msg: string): Error => {
if (opts?.configFile) {
msg = `error reading ${opts.configFile}: ${msg}`
@ -288,18 +288,28 @@ export const parse = async (
break
case LogLevel.Debug:
logger.level = Level.Debug
args.verbose = false
break
case LogLevel.Info:
logger.level = Level.Info
args.verbose = false
break
case LogLevel.Warn:
logger.level = Level.Warning
args.verbose = false
break
case LogLevel.Error:
logger.level = Level.Error
args.verbose = false
break
}
return args
}
export async function setDefaults(args: Args): Promise<Args> {
args = { ...args }
if (!args["user-data-dir"]) {
await copyOldMacOSDataDir()
args["user-data-dir"] = paths.data
@ -353,7 +363,7 @@ export async function readConfigFile(configPath?: string): Promise<Args> {
}
return `--${optName}=${opt}`
})
const args = await parse(configFileArgv, {
const args = parse(configFileArgv, {
configFile: configPath,
})
return {

View File

@ -9,7 +9,7 @@ import { ProxyHttpProvider } from "./app/proxy"
import { StaticHttpProvider } from "./app/static"
import { UpdateHttpProvider } from "./app/update"
import { VscodeHttpProvider } from "./app/vscode"
import { Args, bindAddrFromAllSources, optionDescriptions, parse, readConfigFile } from "./cli"
import { Args, bindAddrFromAllSources, optionDescriptions, parse, readConfigFile, setDefaults } from "./cli"
import { AuthType, HttpServer, HttpServerOptions } from "./http"
import { generateCertificate, hash, open, humanPath } from "./util"
import { ipcMain, wrap } from "./wrapper"
@ -43,6 +43,8 @@ const main = async (cliArgs: Args): Promise<void> => {
}
}
args = await setDefaults(args)
logger.info(`Using user-data-dir ${humanPath(args["user-data-dir"])}`)
logger.trace(`Using extensions-dir ${humanPath(args["extensions-dir"])}`)
@ -127,9 +129,9 @@ const main = async (cliArgs: Args): Promise<void> => {
}
async function entry(): Promise<void> {
const tryParse = async (): Promise<Args> => {
const tryParse = (): Args => {
try {
return await parse(process.argv.slice(2))
return parse(process.argv.slice(2))
} catch (error) {
console.error(error.message)
process.exit(1)