diff --git a/bin/moshcode.mjs b/bin/moshcode.mjs index 2d8f8f7..e1732c4 100755 --- a/bin/moshcode.mjs +++ b/bin/moshcode.mjs @@ -496,7 +496,7 @@ async function main() { } help(); - if (cmd && cmd !== "help") process.exit(1); + if (cmd && !["help", "--help", "-h"].includes(cmd)) process.exit(1); } main(); diff --git a/src/cli-schema.mjs b/src/cli-schema.mjs index 9e4d74c..1d4ae9b 100644 --- a/src/cli-schema.mjs +++ b/src/cli-schema.mjs @@ -23,6 +23,8 @@ export const CORE_CLI_COMMANDS = [ { name: "completion", description: "print a shell completion script" }, { name: "run", description: "run a moshscript" }, { name: "help", description: "show command help" }, + { name: "--help", description: "show command help" }, + { name: "-h", description: "show command help" }, { name: "version", description: "show the installed version" }, { name: "--version", description: "show the installed version" }, { name: "-v", description: "show the installed version" }, diff --git a/test/cli.test.mjs b/test/cli.test.mjs index e1a051b..9905830 100644 --- a/test/cli.test.mjs +++ b/test/cli.test.mjs @@ -22,6 +22,17 @@ test("moshcode --version prints the package version", () => { assert.equal(result.stderr, ""); }); +for (const command of ["help", "--help", "-h"]) { + test(`moshcode ${command} prints help successfully`, () => { + const result = spawnSync(process.execPath, [BIN, command], { + encoding: "utf8", + }); + assert.equal(result.status, 0); + assert.match(result.stdout, /^moshcode .*\n\nusage:/); + assert.equal(result.stderr, ""); + }); +} + for (const command of ["engines", "tools"]) { test(`moshcode ${command} --json prints machine-readable install status`, () => { const result = spawnSync(process.execPath, [BIN, command, "--json"], { diff --git a/test/completion.test.mjs b/test/completion.test.mjs index c8c499a..0c9f4af 100644 --- a/test/completion.test.mjs +++ b/test/completion.test.mjs @@ -55,6 +55,9 @@ test("completion model derives engines, aliases, and tools from their registries assert.ok(top.has(name)); assert.ok(install.has(name)); } + for (const name of ["help", "--help", "-h"]) { + assert.ok(top.has(name)); + } const upgrade = new Set(names(model.upgrade)); for (const { name } of UPGRADE_TARGETS) assert.ok(upgrade.has(name));