Skip to content

Commit

Permalink
fix: restore exit(0) behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
mdonnalley committed Oct 27, 2023
1 parent ccfbf3d commit 0c3fdd7
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 8 deletions.
4 changes: 1 addition & 3 deletions src/command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
6 changes: 2 additions & 4 deletions src/errors/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion test/command/command.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down

0 comments on commit 0c3fdd7

Please sign in to comment.