Conversation
|
This has been implemented as a non-breaking change, so can go after 7.0.0 if there are concerns. |
|
Thanks @abetomo 🎈 |
|
Does this feature allow me to add global options before adding sub commands? Is it then possible to do |
|
@CMCDragonkai |
|
But how do I access these global options inside a subcommand action handler? And will it work if put the option after the subcommand? Our CLI has loads of subcommands. |
|
@CMCDragonkai Please open a new issue if you want a fuller explanation. If I understood your questions correctly, they do not seem to be about this Pull Request but about global options in general. |
|
@shadowspawn |
|
@ruscon If you don't mind, would you please open a new issue to track this? (I have added it to my private backlog in any case.) |
Pull Request
Collected issues and background research in #1229
Problem
Two quite similar problems in how they look on command line, but different use cases.
Related: #598 #797 #1033 #1307 #1426
Related: #1127 #1293
Solution
Add two new routines to alter the parsing of options to be positional. The default behaviour is unchanged.
.enablePositionalOptions()Enable positional options. Positional means global options are specified before subcommands which lets subcommands reuse the same option names, and also enables subcommands to turn on passThroughOptions.
The default behaviour is non-positional (as before) and global options may appear anywhere on the command line.
Positional options makes it different whether an option comes before or after a subcommand. e.g.
.passThroughOptions()Pass through options that come after command-arguments rather than treat them as command-options, so actual command-options come before command-arguments. Turning this on for a subcommand requires positional options to have been enabled on the program (parent commands).
The default behaviour is non-positional (as before) and options may appear before or after command-arguments.
Pass through options makes it different whether an option comes before or after a command-argument. e.g.
ChangeLog
.enablePositionalOptions()to let program and subcommand reuse same option.passThroughOptions()to pass options through to other programs without needing--To Do: