This repository was archived by the owner on Mar 4, 2025. It is now read-only.
feat(cli): add user-friendly exit for unknown options #854
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR has no related issues.
I added a logic for CNA to show help message instead of raw error stack in case a user (like me 1 hour ago) passes unknown options.
By doing so, the user can find what he/she really wanted and copy it quickly, without running
help
command or seeing documentation.Explanation of work
I felt the try-catch block long so I extracted the main part in
run
function.If you prefer inlined version as before, let me know.
How I tested
node lib/cli.js test --unknown-options
, and checked the output (for what I added)node lib/cli.js test
withthrow new Error('Custom Message')
added beforerun
function call, and checked the output (for backward compatibility)node lib/cli.js test
, and checked the output (for backward compatibility, it shows "not empty" error with exit code 0)