-
Notifications
You must be signed in to change notification settings - Fork 86
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
add an attribute on option argument to let from_str_fn
can return Vec<T>
or Option<T>
as-is
#141
Comments
I have a similar request, which would be a way to allow options with multiple values, like |
For repeated args, The |
If you wanted to specifically take a delimited format, you could do that with a new-type pattern around a
|
That works great for me, cheers! |
I already mentioned in the issue description that newtype can solve the problem itself, and even gave a code example. But I think most use cases don't actually need a newtype, and adding one would just create redundant code. So I still prefer to add an option. |
That you did, sorry about missing that (this is what I get when I answer from the e-mail notification and only see the latest message added). One way of doing this is that this is probably doable with a generic type, which could be added to the (with const generics, which I don't remember the state of)
@erickt - What do you think? comma-separated would be more tractable than space-separated (since the parser would see it as a single string, vs. needing to keep passing the next value to the same parser/accumulator). Or do we just tell people to use new-type and do it themselves, since the CLI rubric that we made |
Sure, I like this idea. My main consideration nowadays with things like this to make sure projects can maintain a rubric through code review. I’d be happy to take a patch that adds support for “-some_option=value” as long as it’s easy for a project like Fuchsia to say they don’t want their CLIs support it. for this feature, it seems easy enough to add a “delimiter” feature so users don’t need to undo the new type trick. Maybe we treat a delimiter of |
In some cases I don't expect
Vec<T>
to mean that the argument can be repeated, orOption<T>
to mean that the argument is optional.For example an argument expects a comma-separated list of integers, which I would expect to be parsed by
from_str_fn
asVec<i32>
:The compiler raised error:
I had to create a newtype:
If an attribute can be provided to make
from_str_fn
returnVec<T>
orOption<T>
as-is, the newtype will not be needed.The text was updated successfully, but these errors were encountered: