()
| 5 | import { isChild, wrapper } from "./wrapper" |
| 6 | |
| 7 | async function entry(): Promise<void> { |
| 8 | // There's no need to check flags like --help or to spawn in an existing |
| 9 | // instance for the child process because these would have already happened in |
| 10 | // the parent and the child wouldn't have been spawned. We also get the |
| 11 | // arguments from the parent so we don't have to parse twice and to account |
| 12 | // for environment manipulation (like how PASSWORD gets removed to avoid |
| 13 | // leaking to child processes). |
| 14 | if (isChild(wrapper)) { |
| 15 | const args = await wrapper.handshake() |
| 16 | wrapper.preventExit() |
| 17 | const server = await runCodeServer(args) |
| 18 | wrapper.onDispose(() => server.dispose()) |
| 19 | return |
| 20 | } |
| 21 | |
| 22 | const cliArgs = parse(process.argv.slice(2)) |
| 23 | const configArgs = await readConfigFile(cliArgs.config) |
| 24 | const args = await setDefaults(cliArgs, configArgs) |
| 25 | |
| 26 | if (args.help) { |
| 27 | console.log("code-server", getVersionString()) |
| 28 | console.log("") |
| 29 | console.log(`Usage: code-server [options] [path]`) |
| 30 | console.log(` - Opening a directory: code-server ./path/to/your/project`) |
| 31 | console.log(` - Opening a saved workspace: code-server ./path/to/your/project.code-workspace`) |
| 32 | console.log("") |
| 33 | console.log("Options") |
| 34 | optionDescriptions().forEach((description) => { |
| 35 | console.log("", description) |
| 36 | }) |
| 37 | return |
| 38 | } |
| 39 | |
| 40 | if (args.version) { |
| 41 | if (args.json) { |
| 42 | console.log(getVersionJsonString()) |
| 43 | } else { |
| 44 | console.log(getVersionString()) |
| 45 | } |
| 46 | return |
| 47 | } |
| 48 | |
| 49 | if (shouldSpawnCliProcess(args)) { |
| 50 | logger.debug("Found VS Code arguments; spawning VS Code CLI") |
| 51 | return runCodeCli(args) |
| 52 | } |
| 53 | |
| 54 | const socketPath = await shouldOpenInExistingInstance(cliArgs, args["session-socket"]) |
| 55 | if (socketPath) { |
| 56 | logger.debug("Trying to open in existing instance") |
| 57 | return openInExistingInstance(args, socketPath) |
| 58 | } |
| 59 | |
| 60 | return wrapper.start(args) |
| 61 | } |
| 62 | |
| 63 | entry().catch((error) => { |
| 64 | logger.error(error.message) |
no test coverage detected