Skip to content

Commit 9d8906d

Browse files
committed
Add version format flag
1 parent a26844e commit 9d8906d

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

src/cli.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import product from "vs/platform/product/node/product";
1212
import { ipcMain } from "vs/server/src/ipc";
1313
import { enableCustomMarketplace } from "vs/server/src/marketplace";
1414
import { MainServer } from "vs/server/src/server";
15-
import { AuthType, buildAllowedMessage, enumToArray, generateCertificate, generatePassword, localRequire, open, unpackExecutables } from "vs/server/src/util";
15+
import { AuthType, buildAllowedMessage, enumToArray, FormatType, generateCertificate, generatePassword, localRequire, open, unpackExecutables } from "vs/server/src/util";
1616

1717
const { logger } = localRequire<typeof import("@coder/logger/out/index")>("@coder/logger/out/index");
1818
setUnexpectedErrorHandler((error) => logger.warn(error.message));
@@ -22,6 +22,7 @@ interface Args extends ParsedArgs {
2222
"base-path"?: string;
2323
cert?: string;
2424
"cert-key"?: string;
25+
format?: string;
2526
host?: string;
2627
open?: string;
2728
port?: string;
@@ -66,6 +67,7 @@ const getArgs = (): Args => {
6667
options.push({ id: "cert-key", type: "string", cat: "o", description: "Path to the certificate's key if one was provided." });
6768
options.push({ id: "extra-builtin-extensions-dir", type: "string", cat: "o", description: "Path to an extra builtin extension directory." });
6869
options.push({ id: "extra-extensions-dir", type: "string", cat: "o", description: "Path to an extra user extension directory." });
70+
options.push({ id: "format", type: "string", cat: "o", description: `Format for the version. ${buildAllowedMessage(FormatType)}.` });
6971
options.push({ id: "host", type: "string", cat: "o", description: "Host for the server." });
7072
options.push({ id: "auth", type: "string", cat: "o", description: `The type of authentication to use. ${buildAllowedMessage(AuthType)}.` });
7173
options.push({ id: "open", type: "boolean", cat: "o", description: "Open in the browser on startup." });
@@ -164,7 +166,15 @@ const startCli = (): boolean | Promise<void> => {
164166
}
165167

166168
if (args.version) {
167-
buildVersionMessage(pkg.codeServerVersion, product.commit).split("\n").map((line) => logger.info(line));
169+
if (args.format === "json") {
170+
console.log(JSON.stringify({
171+
codeServerVersion: pkg.codeServerVersion,
172+
commit: product.commit,
173+
vscodeVersion: pkg.version,
174+
}));
175+
} else {
176+
buildVersionMessage(pkg.codeServerVersion, product.commit).split("\n").map((line) => logger.info(line));
177+
}
168178
return true;
169179
}
170180

src/util.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ export enum AuthType {
1616
Password = "password",
1717
}
1818

19+
export enum FormatType {
20+
Json = "json",
21+
}
22+
1923
export const tmpdir = path.join(os.tmpdir(), "code-server");
2024

2125
export const generateCertificate = async (): Promise<{ cert: string, certKey: string }> => {

0 commit comments

Comments
 (0)