From e0a1f1212fa8ba38a47b5aeee0a1cb2f4cd15139 Mon Sep 17 00:00:00 2001 From: John Gee Date: Sun, 13 Jun 2021 11:20:47 +1200 Subject: [PATCH 1/2] Add tips about showing help instead of just missing arguments error --- CHANGELOG.md | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8861c627a..7e26310b3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,39 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. +## [Unreleased] (date goes here) + +### Migration Tips + +If you have a simple program without an action handler, you will now get an error if +there are missing command-arguments. + +``` +program + .option('-d, --debug') + .arguments(''); +program.parse(); +``` + +``` +$ node trivial.js +error: missing required argument 'file' +``` + +If you want to show the help in this situation, you could check the arguments before parsing: + +``` +if (process.argv.length === 2) + program.help(); +program.parse(); +``` + +Or, you might choose to show the help after any user error: + +``` +program.showHelpAfterError(); +``` + ## [8.0.0-2] (2021-06-06) ### Added From e2edc1e414fa7a214e97f1deefa9945b4bf9a230 Mon Sep 17 00:00:00 2001 From: John Gee Date: Mon, 14 Jun 2021 08:37:21 +1200 Subject: [PATCH 2/2] Add block types. Fix indentation. --- CHANGELOG.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7e26310b3..320aef43e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,21 +15,21 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. If you have a simple program without an action handler, you will now get an error if there are missing command-arguments. -``` +```js program - .option('-d, --debug') - .arguments(''); + .option('-d, --debug') + .arguments(''); program.parse(); ``` -``` +```sh $ node trivial.js error: missing required argument 'file' ``` If you want to show the help in this situation, you could check the arguments before parsing: -``` +```js if (process.argv.length === 2) program.help(); program.parse(); @@ -37,7 +37,7 @@ program.parse(); Or, you might choose to show the help after any user error: -``` +```js program.showHelpAfterError(); ```