2020-02-06 19:11:38 +00:00
|
|
|
import * as path from "path"
|
|
|
|
import { logger, Level } from "@coder/logger"
|
2020-02-06 18:29:19 +00:00
|
|
|
import { Args as VsArgs } from "../../lib/vscode/src/vs/server/ipc"
|
2020-02-06 19:11:38 +00:00
|
|
|
import { AuthType } from "./http"
|
|
|
|
import { xdgLocalDir } from "./util"
|
2020-02-06 18:29:19 +00:00
|
|
|
|
|
|
|
export interface Args extends VsArgs {
|
|
|
|
auth?: AuthType
|
|
|
|
"base-path"?: string
|
|
|
|
cert?: string
|
|
|
|
"cert-key"?: string
|
|
|
|
format?: string
|
|
|
|
host?: string
|
|
|
|
json?: boolean
|
|
|
|
open?: boolean
|
|
|
|
port?: string
|
|
|
|
socket?: string
|
|
|
|
version?: boolean
|
|
|
|
_: string[]
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: Implement proper CLI parser.
|
|
|
|
export const parse = (): Args => {
|
|
|
|
const last = process.argv[process.argv.length - 1]
|
2020-02-06 19:11:38 +00:00
|
|
|
const userDataDir = xdgLocalDir
|
|
|
|
const verbose = process.argv.includes("--verbose")
|
|
|
|
const trace = process.argv.includes("--trace")
|
|
|
|
|
|
|
|
if (verbose || trace) {
|
|
|
|
process.env.LOG_LEVEL = "trace"
|
|
|
|
logger.level = Level.Trace
|
|
|
|
}
|
|
|
|
|
2020-02-06 18:29:19 +00:00
|
|
|
return {
|
2020-02-06 19:11:38 +00:00
|
|
|
"extensions-dir": path.join(userDataDir, "extensions"),
|
|
|
|
"user-data-dir": userDataDir,
|
2020-02-06 18:29:19 +00:00
|
|
|
_: last && !last.startsWith("-") ? [last] : [],
|
2020-02-06 19:11:38 +00:00
|
|
|
json: process.argv.includes("--json"),
|
|
|
|
log: process.env.LOG_LEVEL,
|
|
|
|
trace,
|
|
|
|
verbose,
|
|
|
|
version: process.argv.includes("--version"),
|
2020-02-06 18:29:19 +00:00
|
|
|
}
|
|
|
|
}
|