Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"build:app": "vite build",
"dev": "node scripts/dev-server.mjs",
"start": "node dist/cli.js serve",
"test": "tsx src/config.test.ts && tsx src/roots.test.ts && tsx src/skills.test.ts && tsx src/workspaces.test.ts && tsx src/review-checkpoints.test.ts && tsx src/oauth-store.test.ts",
"test": "tsx src/config.test.ts && tsx src/roots.test.ts && tsx src/skills.test.ts && tsx src/workspaces.test.ts && tsx src/review-checkpoints.test.ts && tsx src/oauth-store.test.ts && tsx src/cli.test.ts",
"typecheck": "tsc -p tsconfig.json --noEmit"
},
"keywords": [],
Expand Down
16 changes: 16 additions & 0 deletions src/cli.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import assert from "node:assert/strict";
import { execFileSync } from "node:child_process";
import { readFileSync } from "node:fs";

const packageJson = JSON.parse(readFileSync(new URL("../package.json", import.meta.url), "utf8")) as {
version: string;
};

for (const flag of ["-v", "--version"]) {
const output = execFileSync("node", ["--import", "tsx", "src/cli.ts", flag], {
encoding: "utf8",
env: { ...process.env, DEVSPACE_CONFIG_DIR: "/tmp/devspace-cli-version-test" },
}).trim();

assert.equal(output, packageJson.version);
}
16 changes: 15 additions & 1 deletion src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
} from "./user-config.js";
import { expandHomePath } from "./roots.js";

type Command = "serve" | "init" | "doctor" | "config" | "help";
type Command = "serve" | "init" | "doctor" | "config" | "help" | "version";
const require = createRequire(import.meta.url);
const SUPPORTED_NODE_RANGE = ">=20.12 <27";

Expand All @@ -42,13 +42,17 @@ async function main(argv: string[]): Promise<void> {
case "help":
printHelp();
return;
case "version":
printVersion();
return;
}
}

function normalizeCommand(command: string | undefined): Command {
if (!command || command === "serve" || command === "start") return "serve";
if (command === "init" || command === "doctor" || command === "config") return command;
if (command === "help" || command === "--help" || command === "-h") return "help";
if (command === "version" || command === "--version" || command === "-v") return "version";
throw new Error(`Unknown command: ${command}`);
}

Expand Down Expand Up @@ -264,13 +268,23 @@ function printHelp(): void {
" devspace doctor Show config, runtime, and native dependency status",
" devspace config get Print persisted config",
" devspace config set publicBaseUrl <url|null>",
" devspace -v, --version Print the installed version",
"",
"For temporary tunnels:",
" DEVSPACE_PUBLIC_BASE_URL=https://example.trycloudflare.com devspace serve",
].join("\n"),
);
}

function printVersion(): void {
const packageJson = require("../package.json") as { version?: unknown };
if (typeof packageJson.version !== "string") {
throw new Error("Unable to read DevSpace package version.");
}

console.log(packageJson.version);
}

function normalizeOptionalPublicBaseUrl(value: string): string | null {
const trimmed = value.trim();
if (!trimmed || trimmed === "null" || trimmed === "none") return null;
Expand Down
Loading