-
Notifications
You must be signed in to change notification settings - Fork 1.7k
How To Share Same Slice Destination Among Different Flags #2073
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
Comments
@kudla The approach I would take is to have a single flag for all our values with a custom Value. You would then do something like this
and so on that way you parse the value into your slice/destination after the conversion. Defining multiple flags for this is an overkill IMO. As of now there is no way to share destinations among various flags |
@dearchap Thanks for your reply Anyway regardless the fact I can agree my personal example is too complex I still believe approach of sharing the same destination across different flags would be really helpful anyway in a lot of other cases. E.g. the second example above
In So would it be ok as a feature request for this approach for the future? |
Sure will do. Did you look at the GenericValue in v3 ? |
Oh, great! Looks like it really might help a lot. Yet |
Yes !!! GenericFlag will accept a cli.Value . https://github.com/urfave/cli/blob/main/flag_generic.go#L3 |
Hi!
Please guys. Actually in
v3
how to make several slice flags to share the same destination .What I'm trying is something like this
So it almost works aggregating all the values into a single slice, except it looks like one whatever the flag is being provided at first (initialized) it resets all the values had being populated with previous other flag values.
And actually the more deeper question (story) behind this.
In
v3
how actually to make the set of flags to add values into a same slice of some custom type but being customized by the fine grained params for the each flag individually.In
v2
it was pretty simple by implementingGeneric.Set(value string) error
in
v3
it seams it really something likeValueCreators
andFlagConfig
should be involved for. Still I can't grasp the whole idea to achieve this.As a simple example I can see it something like following
So that to be called as
An to have in the
data
destination respectively something related to[120, 12 * 1024, 100 * 1024 * 1024]
It actually matters to keep the values initial order (so that's why we need the same destination here)
Another case would be something to accumulate a set of inputs but from different encoding sources
So besides the initially described problem with multi int slice flags. The question is
cli.Value
implementation be introduced for that or could it be achieved just on the generic params manipulation levelThank you.
The text was updated successfully, but these errors were encountered: