-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Global options not visible on sub-commands? #66
Comments
That is correct and intentional. Why should the flags on the outer command show up on the inner command? It's the same behavior as in git:
|
I'd be interested in this as well. Whilst this might be the intentional default behaviour, is there a way to work around this, and inherit group options on child commands? Or is the only way to repeat options on every command? |
I have the same problem with likely every CLI program I write with subcommands. As a user I want to have the freedom to place an option "anywhere" (where it logically makes sense) in the command line. Examples:
For what I know, it seems that with Click I only have two choices:
Other CLI frameworks, such as Go's Cobra, have "global flags" for that. Is there absolutely no way to do this with Click? Can we reopen this issue and discuss possible solutions? |
We do not plan to change this. A third solution is to write a |
https://stackoverflow.com/questions/32493912/is-it-possible-to-add-a-global-argument-for-all-subcommands-in-click-based-inter SO example that might fit your use case @bittner |
Thanks Jay! Unfortunately, the example on SO is a bit hard to grasp. We should come up with a simple, easy-to-understand solution and add that to the Click documentation. That would already help. |
An interesting, related discussion is #108 (comment). Includes some usable solutions. |
We would need options such as `--debug` to be global options. Unfortunately, Click doesn't support global options (or group options that are inherited). A deliberate design decision, as a core developer explains. See pallets/click#66
We would need options such as `--debug` to be global options. Unfortunately, Click doesn't support global options (or group options that are inherited). A deliberate design decision, as a core developer explains. See pallets/click#66
Hey there Armin, hope you're doing well 😄
In many cases (as per your Git example), there is a need for certain options to be available across the entire CLI application.
e.g.
Using the exact Git example code provided, the options registered against the global group do not appear in the help of sub-commands.
e.g. when running python git.py --help, we get:
and now when running python git.py clone --help, the repo-home and debug options are no longer shown:
Any ideas?
Thanks heaps
Fotis
The text was updated successfully, but these errors were encountered: