Skip to content

Commit 0559bc2

Browse files
committed
refactor(cli): use Commander exit errors
1 parent 0934c44 commit 0559bc2

1 file changed

Lines changed: 3 additions & 19 deletions

File tree

‎src/cli/setup-onboard-configure-help-fast-path.ts‎

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// Fast help renderer for setup/onboard/configure without loading full CLI startup.
2-
import { Command } from "commander";
2+
import { Command, CommanderError } from "commander";
33
import { VERSION } from "../version.js";
44
import { resolveCliArgvInvocation } from "./argv-invocation.js";
55
import type { ProgramContext } from "./program/context.js";
@@ -13,19 +13,6 @@ const SETUP_ONBOARD_CONFIGURE_HELP_COMMANDS = new Set<SetupOnboardConfigureHelpC
1313
"configure",
1414
]);
1515

16-
function isCommanderParseExit(error: unknown): error is { exitCode: number } {
17-
if (!error || typeof error !== "object") {
18-
return false;
19-
}
20-
const candidate = error as { code?: unknown; exitCode?: unknown };
21-
return (
22-
typeof candidate.exitCode === "number" &&
23-
Number.isInteger(candidate.exitCode) &&
24-
typeof candidate.code === "string" &&
25-
candidate.code.startsWith("commander.")
26-
);
27-
}
28-
2916
function resolveSetupOnboardConfigureHelpCommand(
3017
argv: string[],
3118
): SetupOnboardConfigureHelpCommand | null {
@@ -75,17 +62,14 @@ export async function tryOutputSetupOnboardConfigureHelp(argv: string[]): Promis
7562

7663
const program = new Command();
7764
program.enablePositionalOptions();
78-
program.exitOverride((err) => {
79-
process.exitCode = typeof err.exitCode === "number" ? err.exitCode : 1;
80-
throw err;
81-
});
65+
program.exitOverride();
8266
configureProgramHelp(program, createHelpContext());
8367
await registerHelpCommand(program, command);
8468

8569
try {
8670
await program.parseAsync(argv);
8771
} catch (error) {
88-
if (!isCommanderParseExit(error)) {
72+
if (!(error instanceof CommanderError)) {
8973
throw error;
9074
}
9175
process.exitCode = error.exitCode;

0 commit comments

Comments
 (0)