-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Prefer mut_arg over help_about and version_about #2211
Conversation
It sounds like the conflicting ideas are that the The options are we either:
To address the having to do this globally, or not I see the two ideas as orthogonal. If you mutate a global argument, that mutation should happen prior to global propagation. If that mutation happens after global propagation, that is on purpose (i.e. to change/undo some unwanted propagated value). We just need to be clear about when mutation happens vs when propagation happens. I don't think a
I would suggest running
I don't believe so. If you
Interesting. I hadn't thought about this too much yet. I think eventually a |
I think there is a misunderstanding about global_mut_arg. It is not for global arguments but it is for propagating the mut_arg lambda to all the subcommands. That way users can use this to specify the short for version once at the top App and all the subcommands will follow it. |
I get that, but I mean if an argument is global (i.e. it will be propagated to all child subcommands) and a mutate lambda gets applied to it in the parent, that mutation is "applied" in the parent command, and the already mutated arg is what is actually propagated down to the child subcommand. i.e. there is no need to re-apply that mutation in each child subcommand. The only part this gets a little wacky, is as you noted with how we handle help/version since those aren't real args until the parsing starts. So I'm suggesting potentially making help/version right away as global args when Otherwise, I agree and we would only be able to apply the mutations after help/version are built (i.e. parse time) and would also need some construct for propagating these mutations to child subcommands if applicable which I think is more complex. Edit: Let me know if I'm still off track and missing something 😄 |
I am stuck on making them global args. How would I turn them off in my subcommands? I think people rely on |
@ldm0 Any thoughts on this? |
I agree. I think seperating the
I think it's needed. I get what @kbknapp said. But I think applying
I think they are needed, whether from the standpoint of API elegance or from the standpoint of usefulness. |
Just to confirm, you are saying this is a bad idea, right? |
Nope, I think this is a great idea. These two idea doesn't conflicts. We can have |
That doesnt need to be done later. They can be done now. But that is what I have been trying to do and I find myself stuck on the API design. |
Changing the behavior of |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Several questions:
The original motivation for this PR is that changing the help & version args
short
,long
andhidden
and other stuff wasn't working withmut_arg
.In v2, we have
help_short
,version_short
,help_message
&version_message
which used to set these. But it's definitely not a complete solution because other details likehidden
etc.. can't be set. So, we removed them in favor ofmut_arg
. But sincemut_arg
executes before building thehelp
andversion
args, it needs the whole arg built and not just the one attribute you want to change. (I have added tests cases to reflect this).One other thing we want to think on is recurring changes. Users don't want to keep doing this for every app/subcommand they build. Ideally they want it to propagate from top. We added
help_about
andversion_about
in v3 which propagates. These were requested for v2 originally because users weren't able to set help & version subcommand's about.So, I decided to get some opinion before actually finalising this:
mut_arg
being executed during the build process after building all the args?global_mut_arg
that propagates and does the same asmut_arg
?mut_subcommand
andglobal_mut_subcommand
that behaves similarly but for subcommands? (This will allow us to replacehelp_about
andversion_about
to use this).