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
People wonder how to get the global options from a subcommand.
The current approaches are calling say
program.opts()
if have a variable available for the program, or callingcmd.parent.opts()
from in the action handler. And looping if there are multiple levels of subcommands with options.Related: #243 #476 #1024 (comment) #1155 #1229
The main expected use of the parent property is to get global options: #1475
Solution
Add
.globalOpts()
which returns the combined global options from global/parent commands.I did consider adding a parameter to
.opts()
to return combined local and global options, but I think explicit routine is simpler. Likewise, I wondered adding a configuration option to have the combined options passed into the action handler, but again explicit routine is simpler to understand.ChangeLog
To Do