Files
SeedPass/js/packages/cli/src/main.ts
T
thePR0M3TH3ANandClaude Fable 5 0dfeca8a50 fix: a bare seedpass-js printed help and then reported a bogus error
exitOverride() makes commander throw for everything it would otherwise exit
on -- displaying help and its own usage errors included. The handler only
recognised two of its codes, so running `seedpass-js` with no arguments
printed the help and followed it with `error: (outputHelp)`, and unknown
commands had their message printed twice.

Any commander.* code is now commander's business: honour its exit code and
let it own the message. SeedPass's own errors still print as before.

Found by running the command.

Co-Authored-By: Claude Fable 5 <[email protected]>
2026-08-15 14:19:38 -04:00

29 lines
1.3 KiB
TypeScript

import process from "node:process";
import { buildProgram } from "./program.js";
// Replaced at bundle time; falls back for source runs (tsx / vitest).
declare const __SEEDPASS_VERSION__: string | undefined;
const version = typeof __SEEDPASS_VERSION__ === "string" ? __SEEDPASS_VERSION__ : "0.0.0-dev";
const program = buildProgram();
program.version(version, "-v, --version", "print the seedpass-js version");
try {
await program.parseAsync(process.argv);
} catch (e) {
const err = e as { exitCode?: number; code?: string; message?: string };
// exitOverride() makes commander throw for everything it would otherwise
// exit on — including displaying help or the version, and its own usage
// errors, which it has already written to stderr. Re-reporting those as
// "error: ..." is wrong twice over: a bare `seedpass-js` printed the help
// and then claimed to have failed with "(outputHelp)". Honour commander's
// exit code, but let it own the message.
if (typeof err.code === "string" && err.code.startsWith("commander.")) {
process.exit(typeof err.exitCode === "number" ? err.exitCode : 0);
}
// Anything else is ours, and the message is the useful part.
process.stderr.write(`error: ${err.message ?? String(e)}\n`);
process.exit(typeof err.exitCode === "number" && err.exitCode !== 0 ? err.exitCode : 1);
}