Skip to content

Commit

Permalink
Merge pull request #834 from oclif/mdonnalley/660
Browse files Browse the repository at this point in the history
feat: don't error on exit code 0
  • Loading branch information
mdonnalley committed Oct 19, 2023
2 parents 36cec0f + 02a394b commit 653fa12
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
4 changes: 3 additions & 1 deletion src/command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,9 @@ export abstract class Command {
return Errors.error(input, options as any)
}

public exit(code = 0): never {
public exit(code: number): never
public exit(code: 0): void
public exit(code = 0): void | never {
Errors.exit(code)
}

Expand Down
6 changes: 4 additions & 2 deletions src/errors/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@ export {ExitError} from './errors/exit'
export {ModuleLoadError} from './errors/module-load'
export {handle} from './handle'

export function exit(code = 0): never {
throw new ExitError(code)
export function exit(code = 0) {
if (code !== 0) {
throw new ExitError(code)
}
}

export function error(input: Error | string, options: {exit: false} & PrettyPrintableError): void
Expand Down
3 changes: 1 addition & 2 deletions test/command/command.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,7 @@ describe('command', () => {

return Command.run([])
})
.catch(/EEXIT: 0/)
.it('exits with 0')
.it('exits with 0 does not throw error')

describe('parse', () => {
fancy.stdout().it('has a flag', async (ctx) => {
Expand Down

0 comments on commit 653fa12

Please sign in to comment.