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

fix: print error message and the usage menu for an unknown command line argument #130

Merged
merged 1 commit into from
Feb 12, 2020

Conversation

presto21
Copy link
Contributor

@presto21 presto21 commented Feb 4, 2020

When an unsupported option is given, a single-line error is printed. Now, the usage menu is printed along with the single-line error.

Change:

  • unsupportedOptionError.js modifies the commander code
  • modified index.js file to include the unsupportedOptionError.js file.

Commander code was:

Command.prototype.unknownOption = function(flag) {
if (this._allowUnknownOption) return;
console.error();
console.error(" error: unknown option %s'", flag);
console.error();
process.exit(1);
};

Now:

program.unknownOption = function(flag) {
if (this._allowUnknownOption) return;
console.error();
console.error(" error: unknown option %s'", flag);
console.error();
// this is the extra code added to the function
this.outputHelp();
process.exit(1);
};

@presto21 presto21 requested a review from dpopp07 February 4, 2020 22:23
Copy link
Member

@dpopp07 dpopp07 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work! Modifying the base package is creative and works perfectly. Generally, you want to be wary about doing this but in this situation I think it's okay.

I've left a couple comments to address before I approve. Also, the build is failing so you'll need to address that. It may just be because the linter is complaining about the use of var. If that's the case, it actually would be good to add a test for this change.

src/cli-validator/index.js Outdated Show resolved Hide resolved
src/cli-validator/utils/unsupportedOptionError.js Outdated Show resolved Hide resolved
@presto21 presto21 force-pushed the unsupportedOptionFix branch from 87a3d1a to af538e8 Compare February 5, 2020 21:22
Copy link
Member

@dpopp07 dpopp07 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a couple more comments. Also, it looks like the test failure was just the linting error, so no test is currently exercising the new behavior. You should add a test in either the "errorHandling" or "optionHandling" test suite

src/cli-validator/index.js Outdated Show resolved Hide resolved
src/cli-validator/utils/unsupportedOptionError.js Outdated Show resolved Hide resolved
@presto21 presto21 force-pushed the unsupportedOptionFix branch 4 times, most recently from 67fc612 to 77e5f94 Compare February 11, 2020 22:29
@codecov
Copy link

codecov bot commented Feb 11, 2020

Codecov Report

❗ No coverage uploaded for pull request base (master@05c7164). Click here to learn what that means.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff            @@
##             master     #130   +/-   ##
=========================================
  Coverage          ?   92.82%           
=========================================
  Files             ?       57           
  Lines             ?     2133           
  Branches          ?        0           
=========================================
  Hits              ?     1980           
  Misses            ?      153           
  Partials          ?        0
Impacted Files Coverage Δ
src/cli-validator/utils/modified-commander.js 100% <100%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 05c7164...7c1aba4. Read the comment docs.

@presto21 presto21 force-pushed the unsupportedOptionFix branch from ecf18e4 to 031cbda Compare February 11, 2020 22:51
…e argument

- When an unknown option was present it would only print a single-line error message
- Now it also prints the usage menu
- modified-commander.js modifies the commander code
- modified index.js file to include the modified-commander.js file.
- added a test to exercising the new behavior.
@presto21 presto21 force-pushed the unsupportedOptionFix branch from b3745bb to 7c1aba4 Compare February 12, 2020 15:51
Copy link
Member

@dpopp07 dpopp07 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! 👍

@dpopp07 dpopp07 merged commit def7dcc into master Feb 12, 2020
@dpopp07 dpopp07 deleted the unsupportedOptionFix branch February 12, 2020 18:07
dpopp07 pushed a commit that referenced this pull request Feb 12, 2020
## [0.19.3](v0.19.2...v0.19.3) (2020-02-12)

### Bug Fixes

* print usage menu for an unknown flag ([#130](#130)) ([def7dcc](def7dcc))
@dpopp07
Copy link
Member

dpopp07 commented Feb 12, 2020

🎉 This PR is included in version 0.19.3 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants