Skip to content

Commit 873914e

Browse files
王璨claude
andcommitted
feat: add CLI version flag
Expose dscode --version and -v, and sync the repo version files for the 0.0.6 release. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
1 parent 79d8bc0 commit 873914e

5 files changed

Lines changed: 84 additions & 3 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
```bash
5555
# Node.js >= 20
5656
npm install -g @wangcan26/dscode
57+
dscode --version
5758
dscode
5859
```
5960

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@wangcan26/dscode",
3-
"version": "0.0.2",
3+
"version": "0.0.6",
44
"type": "module",
55
"description": "DeepSeek-native terminal AI agent for digital work — DeepSeek model harness analogous to Claude Code for Claude models.",
66
"bin": {

src/core/main.ts

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,38 @@
1+
import { existsSync, readFileSync } from "node:fs";
2+
import { dirname, join } from "node:path";
3+
import { fileURLToPath } from "node:url";
4+
15
import { loadConfig } from "./config.js";
26
import { Harness } from "./harness.js";
37

48
process.on("unhandledRejection", (reason) => {
59
console.error("[unhandledRejection]", reason);
610
});
711

12+
function readCliVersion(): string {
13+
const currentDir = dirname(fileURLToPath(import.meta.url));
14+
const candidates = [
15+
join(currentDir, "..", "package.json"),
16+
join(currentDir, "..", "..", "package.json"),
17+
];
18+
19+
for (const candidate of candidates) {
20+
if (!existsSync(candidate)) continue;
21+
const pkg = JSON.parse(readFileSync(candidate, "utf8")) as { version?: string };
22+
if (typeof pkg.version === "string" && pkg.version.trim() !== "") {
23+
return pkg.version;
24+
}
25+
}
26+
27+
return "unknown";
28+
}
29+
830
async function main(): Promise<void> {
31+
if (process.argv.slice(2).some((arg) => arg === "--version" || arg === "-v")) {
32+
console.log(readCliVersion());
33+
return;
34+
}
35+
936
const config = loadConfig();
1037

1138
if (config.apiKey) {
@@ -18,4 +45,4 @@ async function main(): Promise<void> {
1845
process.exit(0);
1946
}
2047

21-
main();
48+
main();

tests/core/main.test.ts

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import { describe, expect, it } from "vitest";
2+
import { execFileSync } from "node:child_process";
3+
import { mkdtempSync, readFileSync, writeFileSync } from "node:fs";
4+
import { tmpdir } from "node:os";
5+
import { dirname, join, resolve } from "node:path";
6+
import { fileURLToPath } from "node:url";
7+
8+
const repoRoot = resolve(dirname(fileURLToPath(import.meta.url)), "..", "..");
9+
const packageVersion = JSON.parse(readFileSync(resolve(repoRoot, "package.json"), "utf8")).version;
10+
11+
describe("dscode version flag", () => {
12+
it("prints the package version for --version", () => {
13+
const configHome = mkdtempSync(join(tmpdir(), "dscode-version-"));
14+
writeFileSync(join(configHome, "config.json"), "{}\n", "utf8");
15+
16+
const output = execFileSync(
17+
process.execPath,
18+
["--import", "tsx", resolve(repoRoot, "src/core/main.ts"), "--version"],
19+
{
20+
cwd: repoRoot,
21+
env: {
22+
...process.env,
23+
DSCODE_CONFIG_HOME: configHome,
24+
DSCODE_DATA_HOME: configHome,
25+
},
26+
encoding: "utf8",
27+
},
28+
);
29+
30+
expect(output.trim()).toBe(packageVersion);
31+
});
32+
33+
it("prints the package version for -v", () => {
34+
const configHome = mkdtempSync(join(tmpdir(), "dscode-version-"));
35+
writeFileSync(join(configHome, "config.json"), "{}\n", "utf8");
36+
37+
const output = execFileSync(
38+
process.execPath,
39+
["--import", "tsx", resolve(repoRoot, "src/core/main.ts"), "-v"],
40+
{
41+
cwd: repoRoot,
42+
env: {
43+
...process.env,
44+
DSCODE_CONFIG_HOME: configHome,
45+
DSCODE_DATA_HOME: configHome,
46+
},
47+
encoding: "utf8",
48+
},
49+
);
50+
51+
expect(output.trim()).toBe(packageVersion);
52+
});
53+
});

0 commit comments

Comments
 (0)