From 2bcfee78de27598ee532c02d9aa643a44b48b99f Mon Sep 17 00:00:00 2001 From: Sindre Sorhus Date: Mon, 5 Nov 2018 16:30:36 +0700 Subject: [PATCH] Add `hardRejection` option Fixes #94 --- index.js | 9 ++++++--- readme.md | 7 +++++++ 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index 7dd86ab..1da76c7 100644 --- a/index.js +++ b/index.js @@ -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 = ''; @@ -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')) { diff --git a/readme.md b/readme.md index 78e6f31..6da84c2 100644 --- a/readme.md +++ b/readme.md @@ -235,6 +235,13 @@ const cli = meow(` */ ``` +##### hardRejection + +Type: `boolean`
+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.