Skip to content

Commit b7e3daa

Browse files
fix(cli): return success for help aliases
1 parent 142f8f0 commit b7e3daa

4 files changed

Lines changed: 17 additions & 1 deletion

File tree

bin/moshcode.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -496,7 +496,7 @@ async function main() {
496496
}
497497

498498
help();
499-
if (cmd && cmd !== "help") process.exit(1);
499+
if (cmd && !["help", "--help", "-h"].includes(cmd)) process.exit(1);
500500
}
501501

502502
main();

src/cli-schema.mjs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ export const CORE_CLI_COMMANDS = [
2323
{ name: "completion", description: "print a shell completion script" },
2424
{ name: "run", description: "run a moshscript" },
2525
{ name: "help", description: "show command help" },
26+
{ name: "--help", description: "show command help" },
27+
{ name: "-h", description: "show command help" },
2628
{ name: "version", description: "show the installed version" },
2729
{ name: "--version", description: "show the installed version" },
2830
{ name: "-v", description: "show the installed version" },

test/cli.test.mjs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,17 @@ test("moshcode --version prints the package version", () => {
2222
assert.equal(result.stderr, "");
2323
});
2424

25+
for (const command of ["help", "--help", "-h"]) {
26+
test(`moshcode ${command} prints help successfully`, () => {
27+
const result = spawnSync(process.execPath, [BIN, command], {
28+
encoding: "utf8",
29+
});
30+
assert.equal(result.status, 0);
31+
assert.match(result.stdout, /^moshcode .*\n\nusage:/);
32+
assert.equal(result.stderr, "");
33+
});
34+
}
35+
2536
for (const command of ["engines", "tools"]) {
2637
test(`moshcode ${command} --json prints machine-readable install status`, () => {
2738
const result = spawnSync(process.execPath, [BIN, command, "--json"], {

test/completion.test.mjs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@ test("completion model derives engines, aliases, and tools from their registries
5555
assert.ok(top.has(name));
5656
assert.ok(install.has(name));
5757
}
58+
for (const name of ["help", "--help", "-h"]) {
59+
assert.ok(top.has(name));
60+
}
5861

5962
const upgrade = new Set(names(model.upgrade));
6063
for (const { name } of UPGRADE_TARGETS) assert.ok(upgrade.has(name));

0 commit comments

Comments
 (0)