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 bin/moshcode.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
2 changes: 2 additions & 0 deletions src/cli-schema.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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" },
Expand Down
11 changes: 11 additions & 0 deletions test/cli.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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"], {
Expand Down
3 changes: 3 additions & 0 deletions test/completion.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
Loading