-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Change to safe storage of options by default, and change action parameters #1409
Merged
shadowspawn
merged 26 commits into
tj:release/7.x
from
shadowspawn:feature/safe-options-by-default
Dec 14, 2020
Merged
Change to safe storage of options by default, and change action parameters #1409
shadowspawn
merged 26 commits into
tj:release/7.x
from
shadowspawn:feature/safe-options-by-default
Dec 14, 2020
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This was referenced Dec 3, 2020
Closed
Closed
Finished first pass through code and README and examples, including migration tips in the CHANGELOG. I intend to update the Examples section in the README next. Update: added single command example and tidied multi-command example. |
3 tasks
This was referenced Jan 15, 2021
shadowspawn
removed
the
pending release
Merged into a branch for a future release, but not released yet
label
Jan 16, 2021
This was referenced Mar 8, 2021
This was referenced Mar 15, 2021
davidjb
added a commit
to davidjb/clean-css-cli
that referenced
this pull request
May 5, 2021
This change removes mention of the `--level` option which never existed. In versions earlier than 5.0.0, clean-css-cli used to accept the invalid option silently. With versions > 5.0.0, trying to use the option results in the following: `error: unknown option '--level'`. The root cause of the change the upgrade to [commander v7.0.0](tj/commander.js#1409), where unknown (excess) command arguments are now raised as an error.
nickebbitt
added a commit
to nickebbitt/helm-test
that referenced
this pull request
Jun 17, 2021
commander.js changed the way it handles options which broke this. See: - https://github.com/tj/commander.js/blob/master/CHANGELOG.md\#changed-2 - tj/commander.js#1409 Co-authored-by: Michael Eves <[email protected]>
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
2 tasks
maxwell-k
added a commit
to maxwell-k/a4
that referenced
this pull request
Jun 20, 2022
- In version 7 there was a breaking change https://github.com/tj/commander.js/blob/master/CHANGELOG.md#700-2021-01-15 - By default, options are no longer available on program tj/commander.js#1409 - Updated code to follow the quick start example https://github.com/tj/commander.js#quick-start
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Pull Request
Problem
This has not worked out as nicely as hoped for moving to safe options incrementally! The various combinations make implementations inconsistent, make it hard to write examples that work whatever the settings, and make it harder to write write a generic action handler.
Solution
These are BREAKING changes for many existing programs. But hopefully the code changes required are small and easy!
.storeOptionsAsProperties(false)
.This affects especially use of program options.
The array of extra args is gone, but one of the common uses was to show an error for excess/unexpected command-arguments. There is now support for Commander to display an error for excess command-arguments, and this has been turned on by default in this PR. See #1407
The method
.passCommandToAction()
is gone. No longer needed with this pattern, the options and command are always available as parameters.Lots of files changed:
ChangeLog
Changed
program.opts()
.storeOptionsAsProperties()
Added
.allowExcessArguments()
Deleted
.passCommandToAction()
Migration Tips
The biggest change is the parsed option values. Previously the options were stored by default as properties on the command object, and now the options are stored separately.
If you wish to restore the old behaviour and get running quickly you can call
.storeOptionsAsProperties()
.To allow you to move to the new code patterns incrementally, the action handler will be passed the command twice,
to match the new "options" and "command" parameters (see below).
program options
Use the
.opts()
method to access the options. This is available on any command but is used most with the program.action handler
The action handler gets passed a parameter for each command-argument you declared. Previously by default the next parameter was the command object with the options as properties. Now the next two parameters are instead the options and the command. If you
only accessed the options there may be no code changes required.
If you already set
.storeOptionsAsProperties(false)
you may still need to adjust your code.excess command-arguments
There is now an error if there are too many command-arguments on the command line (only checked if there is an action handler).
If the extra arguments are supported by your command then you can either declare the expected arguments, or allow excess arguments.