cmd-ts icon indicating copy to clipboard operation
cmd-ts copied to clipboard

Ability to throw something to trigger logging message w/specific exit code, no stack trace

Open cspotcode opened this issue 3 years ago • 0 comments

I would like to abort a CLI handler by throwing something, but control the exit code, and not see a stack trace.

I can think of two ways this might work:

a) ability to throw new CliError('message to log', exitCode) b) optional errorHandler callback receives a thrown error and decides how to handle it. For example, any errors from an underlying http client can be logged in a specific format and exit with a specific exit code

I tried to use Exit for this, but it's not exported, and comments say it's an internal implementation detail of cmd-ts. https://github.com/Schniz/cmd-ts/blob/0d29e91615f85da9bc90d138b03f96c718d623a6/src/effects.ts#L27

I'm using runSafely, but I had to copy the implementation of run into my code, and it's undocumented. Could this be as simple as explaining runSafely in the README?

cspotcode avatar Feb 03 '23 04:02 cspotcode