exec-promise
Testable CLIs with promises
Features
- executes the passed function with command line arguments
- wait for completion (sync or promise) before stopping Node
- in case of exception: pretty print the value and exit with exit code 1
- in case of returned value (not undefined):
- if valid exit code (integer), exit Node with it
- otherwise, pretty print it
Introduction
TODO
- executables should be testable
- the execution flow should be predictable and followable (promises)
Install
Download manually or with package-manager.
npm install --save exec-promise
This library requires promises support, for Node versions prior to 0.12 see
this page to
enable them.
Example
ES 2015
import execPromise from 'exec-promise'
execPromise(async args => {
})
ES5
module.exports = function (args) {
if (args.indexOf('-h') !== -1) {
return 'Usage: my-program [-h | -v]'
}
if (args.indexOf('-v') !== -1) {
var pkg = require('./package')
return 'MyProgram version ' + pkg.version
}
var server = require('http').createServer()
server.listen(80)
return require('event-to-promise')(server, 'close')
}
if (!module.parent) {
require('exec-promise')(module.exports)
}
Contributing
Contributions are very welcome, either on the documentation or on
the code.
You may:
- report any issue
you've encountered;
- fork and create a pull request.
License
ISC © Julien Fontanet