yargs-promise-handler
Adds support for promises to yargs handlers and allows them to be composable.
NOTE: This module is deprecated because yargs now support async commands!
Installation
$ npm install yargs-promise-handler --save
Why?
yargs
does not support command handlers that return promises. Users must handle promises and call process.exit()
manually.
This packages does exactly that under the hood and exposes the original promise under handler.promise()
to allow handlers to be composable.
Usage
// commands/randomconst command = 'random';const describe = 'A command that either fails or succeeds based on randomness'; const builder = argv;const handler = ;
The code above will either exit with code 0
or 5
if the promise either fulfills or rejects respectively.
Note that if the error.exitCode
is undefined, it will default to 1
.
The second argument of promiseHandler
accepts an options object:
logError
: Callconsole.error(err)
before exiting if the promise fails, defaults totrue
Tests
$ npm test
$ npm test -- --watch
during development