-
-
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
Please support flatten
ing an Args
and mutating arguments before merging
#5050
Comments
The overall need for flattening was brought up in #3117 but the design was deemed too complicated and rejected. The thing we overlooked in our discussion over zulip which is brought up in #3117 is that we need unique There are other ways that this design could be useful, like with #3221 and #3513. In #3513, I was concerned about not being able to uniquify the
|
Interesting. When flattening a struct into a parent struct, does the child's impl still need to be used, or could the parent become responsible for filling in the fields merged from the child using its own IDs? I'm still interested in a design that would allow for flattening multiple copies of the same struct into a parent while using different argument names, IDs, help text, and potentially other changes. I'm not at all attached to any particular implementation path for doing so, though. |
The parent would need to know the field IDs, their clap type, how to consstruct the struct, etc.
So far I've not been able to come up with a feasible design that can deal with how little each side knows about the other without geting into more complex (and runtime vs compile time) trait interactions. |
Would it help if flattenable structs had to do a different derive, like Would it help if flattenable structs had a const-generic template parameter that augments the ID? (That has usability issues, but it seems better than nothing.) Would it help if the combination of flatten and modification just always resulted in doing some things at runtime rather than compile time? At least for my use cases, a tiny bit of runtime overhead when parsing arguments would not be a problem.
Right. And it can easily get all that at runtime, but not at compile time from a separate derive... |
If you mean a different derive + trait, then that is just another way of expressing the same idea of "pass information at runtime". Personally, extra trait and derive doesn't seem like the ideal way because that makes the user experience worse
The derive would need to recognize that it should use this, on both sides. Most likely an attribute. We need to add attributes more related to generics (e.g. wanting to make parsing generic over the help system), just haven't decided on how to express all of that.
My more general concern is that there are a lot of these one off cases for more runtime communication between derives and being hesitant in drawing the line for where it is acceptable to do so and where to say no, so I've just always said no. Without the extra trait mentioned above, we also have to be careful of compatibility, not just of trait definition changes but codegen changes for interacting with by-hand impls of the traits. More specifically, whether we get the information from a generic parameter or from a runtime parameter, we need to do string joins to pass into clap which requires the |
Many subcommands in I'd be happy if the solution were a bit simpler, but I'm happy that it works. I think something like this would also solve your problem, @joshtriplett. |
Please complete the following tasks
Clap Version
4.3.19
Describe your use case
I have a group of four arguments that repeat three different times with different names and descriptions. Right now, I have to manually duplicate the arguments with different names and descriptions, and then I manually transform each group of four back into a struct. I'd like to have a struct deriving
Args
that contains those four arguments, and flatten three copies of it into a parent struct, callingmut_arg
on the child along the way.Right now, this doesn't work because the arguments all get inserted first, and will conflict, before
mut_arg
runs.Also, even if this did work, it'd require calling
mut_arg
four times, once for each child argument.Describe the solution you'd like
Based on discussion with @epage: could we implement the combination of
flatten
andmut_arg
in a different way, by first turning the child struct into a full standaloneCommand
, then running the suppliedmut_arg
on thatCommand
, and then merge theCommand
into the parentCommand
?In addition, could we have a
mut_args
that runs on all arguments of the child struct? That'd make it easy to systematically modifyid
,long
, andhelp
, for every argument.Alternatives, if applicable
No response
Additional Context
No response
The text was updated successfully, but these errors were encountered: