Comparing version 1.0.0 to 1.1.0
10
app.js
@@ -13,6 +13,10 @@ 'use strict' | ||
let exited = false | ||
onExit(() => { | ||
onExit((code, signal) => { | ||
if (started && !exited) { | ||
console.error('Abnormal exit: Promises not resolved') | ||
process.exit(1) | ||
if (signal) { | ||
console.error('Abnormal exit:', signal) | ||
} else { | ||
console.error('Abnormal exit: Promises not resolved') | ||
} | ||
process.exit(code || 1) | ||
} | ||
@@ -19,0 +23,0 @@ }) |
{ | ||
"name": "@iarna/cli", | ||
"version": "1.0.0", | ||
"description": "", | ||
"version": "1.1.0", | ||
"description": "Some simple CLI scaffolding for promise returning applications.", | ||
"main": "app.js", | ||
@@ -19,3 +19,12 @@ "scripts": { | ||
"app.js" | ||
] | ||
], | ||
"devDependencies": {}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/iarna/cli.git" | ||
}, | ||
"bugs": { | ||
"url": "https://github.com/iarna/cli/issues" | ||
}, | ||
"homepage": "https://github.com/iarna/cli#readme" | ||
} |
@@ -7,6 +7,9 @@ # @iarna/cli | ||
``` | ||
`example.js` | ||
```js | ||
require('@iarna/cli')(main) | ||
.boolean('silent') | ||
.boolean('exit') | ||
.boolean('error') | ||
.boolean('reject') | ||
.version() | ||
@@ -18,3 +21,5 @@ .help() | ||
console.log('Got:', arg1, arg2, arg3) | ||
if (opts.exit) process.exit() | ||
if (opts.error) throw new Error('throw') | ||
if (opts.reject) return Promise.reject(new Error('reject')) | ||
return new Promise(resolve => setTimeout(resolve, 10000)) | ||
@@ -24,2 +29,36 @@ } | ||
```console | ||
$ node example hello there world | ||
Starting up! | ||
Got: hello there world | ||
$ node example hello there world | ||
Starting up! | ||
Got: hello there world | ||
^C | ||
Abnormal exit: SIGINT | ||
$ node example --silent hello there world | ||
Got: hello there world | ||
$ node example --silent hello there world --exit | ||
Got: hello there world | ||
Abnormal exit: Promises not resolved | ||
$ node example --silent hello there world --error | ||
Abnormal exit: Promises not resolved | ||
Got: hello there world | ||
Error: throw | ||
at main (/Users/rebecca/code/cli/example.js:11:25) | ||
at Immediate.setImmediate (/Users/rebecca/code/cli/app.js:38:32) | ||
at runCallback (timers.js:800:20) | ||
at tryOnImmediate (timers.js:762:5) | ||
at processImmediate [as _immediateCallback] (timers.js:733:5) | ||
$ node example --silent hello there world --reject | ||
Got: hello there world | ||
Error: reject | ||
at main (/Users/rebecca/code/cli/example.js:12:42) | ||
at Immediate.setImmediate [as _onImmediate] (/Users/rebecca/code/cli/app.js:38:32) | ||
at runCallback (timers.js:800:20) | ||
at tryOnImmediate (timers.js:762:5) | ||
at processImmediate [as _immediateCallback] (timers.js:733:5) | ||
$ | ||
``` | ||
## WHAT YOU GET | ||
@@ -59,3 +98,4 @@ | ||
Your entry point function should look like this: | ||
Your entry point function can be named anything, but it needs to return a | ||
promise and it takes arguments like this: | ||
@@ -62,0 +102,0 @@ `main(opts, arg1, arg2, …, argn) → Promise` |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No bug tracker
MaintenancePackage does not have a linked bug tracker in package.json.
Found 1 instance in 1 package
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
No website
QualityPackage does not have a website.
Found 1 instance in 1 package
8985
5
51
1
1
102
1