Allow specifying a workspace on the command line

Fixes #1535.
This commit is contained in:
Asher 2020-04-16 11:50:53 -05:00
parent 29b6115c77
commit 974d4cb8fc
No known key found for this signature in database
GPG Key ID: D63C1EF81242354A
2 changed files with 16 additions and 3 deletions

View File

@ -139,8 +139,8 @@ code-server tries the following in order:
1. The `workspace` query parameter. 1. The `workspace` query parameter.
2. The `folder` query parameter. 2. The `folder` query parameter.
3. The directory passed on the command line. 3. The workspace or directory passed on the command line.
4. The last opened workspace or folder. 4. The last opened workspace or directory.
## Enterprise ## Enterprise

View File

@ -1,6 +1,7 @@
import { field, logger } from "@coder/logger" import { field, logger } from "@coder/logger"
import * as cp from "child_process" import * as cp from "child_process"
import * as crypto from "crypto" import * as crypto from "crypto"
import * as fs from "fs-extra"
import * as http from "http" import * as http from "http"
import * as net from "net" import * as net from "net"
import * as path from "path" import * as path from "path"
@ -209,6 +210,15 @@ export class VscodeHttpProvider extends HttpProvider {
private async getFirstPath( private async getFirstPath(
startPaths: Array<{ url?: string | string[]; workspace?: boolean } | undefined>, startPaths: Array<{ url?: string | string[]; workspace?: boolean } | undefined>,
): Promise<StartPath | undefined> { ): Promise<StartPath | undefined> {
const isFile = async (path: string): Promise<boolean> => {
try {
const stat = await fs.stat(path)
return stat.isFile()
} catch (error) {
logger.warn(error.message)
return false
}
}
for (let i = 0; i < startPaths.length; ++i) { for (let i = 0; i < startPaths.length; ++i) {
const startPath = startPaths[i] const startPath = startPaths[i]
const url = const url =
@ -216,7 +226,10 @@ export class VscodeHttpProvider extends HttpProvider {
if (startPath && url) { if (startPath && url) {
return { return {
url, url,
workspace: !!startPath.workspace, // The only time `workspace` is undefined is for the command-line
// argument, in which case it's a path (not a URL) so we can stat it
// without having to parse it.
workspace: typeof startPath.workspace !== "undefined" ? startPath.workspace : await isFile(url),
} }
} }
} }