Skip to content

Commit

Permalink
Add hardRejection option
Browse files Browse the repository at this point in the history
Fixes #94
  • Loading branch information
sindresorhus committed Nov 5, 2018
1 parent f60c26e commit 2bcfee7
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
9 changes: 6 additions & 3 deletions index.js
Expand Up @@ -15,8 +15,6 @@ delete require.cache[__filename];
const parentDir = path.dirname(module.parent.filename);

module.exports = (helpMessage, options) => {
hardRejection();

if (typeof helpMessage === 'object' && !Array.isArray(helpMessage)) {
options = helpMessage;
helpMessage = '';
Expand All @@ -33,9 +31,14 @@ module.exports = (helpMessage, options) => {
help: helpMessage,
autoHelp: true,
autoVersion: true,
booleanDefault: false
booleanDefault: false,
hardRejection: true
}, options);

if (options.hardRejection) {
hardRejection();
}

const minimistFlags = options.flags && typeof options.booleanDefault !== 'undefined' ? Object.keys(options.flags).reduce(
(flags, flag) => {
if (flags[flag].type === 'boolean' && !Object.prototype.hasOwnProperty.call(flags[flag], 'default')) {
Expand Down
7 changes: 7 additions & 0 deletions readme.md
Expand Up @@ -235,6 +235,13 @@ const cli = meow(`
*/
```

##### hardRejection

Type: `boolean`<br>
Default: `true`

Whether to use [`hard-rejection`](https://github.com/sindresorhus/hard-rejection) or not. Disabling this can be useful if you need to handle `process.on('unhandledRejection')` yourself.

## Promises

Meow will make unhandled rejected promises [fail hard](https://github.com/sindresorhus/hard-rejection) instead of the default silent fail. Meaning you don't have to manually `.catch()` promises used in your CLI.
Expand Down

0 comments on commit 2bcfee7

Please sign in to comment.