You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Sometimes options have an optional argument, for example in rustfmt we can use either --help or --help=<topic>.
In order to achieve this we can use Arg::min_values(0) in clap (as described here: clap-rs/clap#892), but there is no way to directly specify it in structopt. Using Option<String> type for a field would fail to distinguish between no option provided at all and an option without an argument. It will return None for both.
It looks like a possible way to support it would be to use Option<Option<String>> field type which can lead to min_values(0) in generated clap code.
Just so people here are aware: I feel like the changelog notes don't do this nice feature justice! I had no idea why I should care about Option<Option<T>>, but it DOES make sense to see cmd [--opt[=value]]. Perhaps the CHANGELOG could be tweaked so this interesting feature could be telegraphed better? :)
@ErichDonGubler Thanks for your feedback! Indeed, I think mentioning Option<Option<T>> in the ChangeLog is more like a leak of implementation detail than a proper feature advertisement :) Your formulation is much better, I am happy to change that. Please let me know if you want to do this and send a PR, otherwise I can do it myself.
Activity
sphynx commentedon May 27, 2019
BTW, I can try to implement a fix for this issue, if you think it's not too hard and doesn't lead to any serious changes in the code.
TeXitoi commentedon May 27, 2019
I'll accept a PR adding support of
Option<Option<T>>sphynx commentedon May 27, 2019
OK, I am working on it.
ErichDonGubler commentedon May 30, 2019
Just so people here are aware: I feel like the changelog notes don't do this nice feature justice! I had no idea why I should care about
Option<Option<T>>, but it DOES make sense to seecmd [--opt[=value]]. Perhaps the CHANGELOG could be tweaked so this interesting feature could be telegraphed better? :)TeXitoi commentedon May 30, 2019
Feel free to open a PR.
TeXitoi commentedon May 30, 2019
If you have ideas of improvement of the doc at the same time, any improvement on this side is very welcome.
sphynx commentedon May 30, 2019
@ErichDonGubler Thanks for your feedback! Indeed, I think mentioning
Option<Option<T>>in the ChangeLog is more like a leak of implementation detail than a proper feature advertisement :) Your formulation is much better, I am happy to change that. Please let me know if you want to do this and send a PR, otherwise I can do it myself.ErichDonGubler commentedon May 31, 2019
I'll be able to get to this probably by Wednesday -- but if you want to take care of it before then, consider my interest relinquished. :)
sphynx commentedon Jun 1, 2019
No worries, I've prepared the pull request with a small update in ChangeLog. Thanks again for your suggestion.