Skip to content

Commit de4244b

Browse files
committed
fix(cli): print package version
1 parent 8446bfc commit de4244b

2 files changed

Lines changed: 19 additions & 0 deletions

File tree

bin/moshcode.mjs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import { locate, tilde } from "../src/pwd.mjs";
2020
import { createPrd, listPrds, authoringPrompt } from "../src/prd.mjs";
2121
import { login, loginDevice, whoami, logout } from "../src/auth.mjs";
2222
import { tui } from "../src/tui.mjs";
23+
import { moshcodeVersion } from "../src/ui.mjs";
2324

2425
const HERE = path.dirname(fileURLToPath(import.meta.url));
2526
const EXAMPLE = path.join(HERE, "..", "examples", "alive.mosh");
@@ -171,6 +172,11 @@ async function main() {
171172
// No args → open the interactive TUI shell (/agents <engine>, etc.).
172173
if (cmd === undefined) return tui();
173174

175+
if (cmd === "--version" || cmd === "-v" || cmd === "version") {
176+
console.log(moshcodeVersion() || "unknown");
177+
return;
178+
}
179+
174180
if (cmd === "engines") {
175181
printEngineStatus();
176182
return;

test/cli.test.mjs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,25 @@
11
import assert from "node:assert/strict";
22
import test from "node:test";
3+
import { readFileSync } from "node:fs";
4+
import { spawnSync } from "node:child_process";
5+
import { fileURLToPath } from "node:url";
36

47
import { runMoshcode, cliVerb, runAi } from "../src/cli.mjs";
58
import { aiExecArgs, pickAiEngine } from "../src/engines.mjs";
69
import { moshVocabulary } from "../src/commands.mjs";
710
import { runScript } from "../src/runtime.mjs";
811
import { createRegistry } from "../src/registry.mjs";
912

13+
test("moshcode --version prints the package version", () => {
14+
const expected = JSON.parse(readFileSync(new URL("../package.json", import.meta.url), "utf8")).version;
15+
const result = spawnSync(process.execPath, [fileURLToPath(new URL("../bin/moshcode.mjs", import.meta.url)), "--version"], {
16+
encoding: "utf8",
17+
});
18+
assert.equal(result.status, 0);
19+
assert.equal(result.stdout.trim(), expected);
20+
assert.equal(result.stderr, "");
21+
});
22+
1023
function dryCtx() {
1124
return { dryRun: true, lines: [], out(l) { this.lines.push(l); } };
1225
}

0 commit comments

Comments
 (0)