Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check command-arguments even without action handler #1502


Copy link

@shadowspawn shadowspawn commented Apr 10, 2021

Pull Request


The number of command-arguments is only checked if there is an action handler. This means no checking for simple programs which fall-through to processing the results of the parsing in following code.

Fixes #1493


Follow in the footsteps of the refactored tests for options. Both the option and command-argument tests were originally tied to the implementation of the action handler. They have now been separated out to be called where appropriate.

Check for missing required command-arguments, or excess command-arguments if enabled, in programs without an action handler.


  • the number of command-arguments is now checked for programs without an action handler

@shadowspawn shadowspawn added the semver: major label Apr 10, 2021
@shadowspawn shadowspawn added this to the v8.0.0 milestone Apr 10, 2021
index.js Outdated Show resolved Hide resolved
Copy link

@abetomo abetomo left a comment

I commented on the naming, but the fix is LGTM.

@shadowspawn shadowspawn merged commit 0504945 into tj:release/8.x Apr 11, 2021
9 checks passed
@shadowspawn shadowspawn deleted the feature/check_arguments_without_action_handler_2 branch Apr 11, 2021
@shadowspawn shadowspawn added the pending release label Apr 11, 2021
Copy link
Collaborator Author

shadowspawn commented May 29, 2021

Note for future readers. Missing command-arguments will now cause an error whether or not there is an action handler. This changes the behaviour for simple single command programs.

$ pizza
error: missing required argument 'file'

If you want to just display the help if the user does not supply any arguments, you could check before calling parse like:

if (process.argv.length === 2);

Also, see .showHelpAfterError() to change the default behaviour to include extra help.

@shadowspawn shadowspawn removed the pending release label Jun 25, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
semver: major
None yet

Successfully merging this pull request may close these issues.

None yet

2 participants