Flag takes optional value #1354
-
There are times when it is necessary to interpret an option as a flag when it has no value, so for example in cargo:
should run an example, whereas
should print available examples. This could be achieved if clap allowed specifying that the value part of the option was optional. It could be signalled by |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 2 replies
-
I have a very similar use case in my own application. I want Running The first thing that came to mind is a In the meantime, I switched my project to getopts, using |
Beta Was this translation helpful? Give feedback.
-
It would be nice to have this "optional option" feature. Same example of usage:
|
Beta Was this translation helpful? Give feedback.
-
This is supported via:
|
Beta Was this translation helpful? Give feedback.
This is supported via:
is_present
, if false - no option were passedvalue_of
--example val
will be mapped toSome(val)
--example
will be mapped toNone