From 0c3fdd7a7e3bfe605274d69894e9a2fba8c2e3d7 Mon Sep 17 00:00:00 2001 From: Mike Donnalley Date: Fri, 27 Oct 2023 12:49:19 -0600 Subject: [PATCH] fix: restore exit(0) behavior --- src/command.ts | 4 +--- src/errors/index.ts | 6 ++---- test/command/command.test.ts | 3 ++- 3 files changed, 5 insertions(+), 8 deletions(-) diff --git a/src/command.ts b/src/command.ts index 1f7e103ef..b93afb8b0 100644 --- a/src/command.ts +++ b/src/command.ts @@ -210,9 +210,7 @@ export abstract class Command { return Errors.error(input, options as any) } - public exit(code: number): never - public exit(code: 0): void - public exit(code = 0): void | never { + public exit(code = 0): never { Errors.exit(code) } diff --git a/src/errors/index.ts b/src/errors/index.ts index 873d61635..ce120a502 100644 --- a/src/errors/index.ts +++ b/src/errors/index.ts @@ -11,10 +11,8 @@ export {ExitError} from './errors/exit' export {ModuleLoadError} from './errors/module-load' export {handle} from './handle' -export function exit(code = 0) { - if (code !== 0) { - throw new ExitError(code) - } +export function exit(code = 0): never { + throw new ExitError(code) } export function error(input: Error | string, options: {exit: false} & PrettyPrintableError): void diff --git a/test/command/command.test.ts b/test/command/command.test.ts index c86f3336e..35f33ea4d 100644 --- a/test/command/command.test.ts +++ b/test/command/command.test.ts @@ -68,7 +68,8 @@ describe('command', () => { return Command.run([]) }) - .it('exits with 0 does not throw error') + .catch(/EEXIT: 0/) + .it('exits with 0') describe('parse', () => { fancy.stdout().it('has a flag', async (ctx) => {