-
-
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
Options shared by a root command and its subCommands #1426
Comments
The root command parses its options from anywhere on the command line, so it consumes the option first before the subcommand. The relevant line in the README is:
You can add and access a common option on the root command, or add it to all your subcommands. A visible difference to the user is where in the help the option appears. Do you think of it as a "program" option on the root command, or a common option which every subcommand has locally? There is an open issue with collected reports and research: #1229 |
Thank you for the explanation. |
Pull Request opened to add |
Opened poll on possible enhancements to global options: #1551 |
Opened a draft PR for |
I had an issue that took me a long time to figure out and fix. It is about an
option
that I add to all the commands of my application:-s
for "silent". When this option is set, a command will disable all outputs when running.Since this is a global option that I add to all commands, I created a
addGlobalOptions(command)
function and I call it for every command.The issue is that I was also calling
addGlobalOptions()
on the root Command!My program looks a bit like:
In
addSubCommands
, each command has the global options added too, usingaddGlobalOptions
.By calling
addGlobalOptions
on the root "commander" Command, a subCommand would always receiveundefined
for the-s
argument, even when specified by the user! By removing the global options on the root "commander" Command,true
is received correctly.I did not find anything in the documentation about this? What is the expected behavior when an option is shared between a root Command and one of its subCommand? Or maybe I'm doing something wrong?
The text was updated successfully, but these errors were encountered: