This repository was archived by the owner on Jan 1, 2022. It is now read-only.
Simplify the takes_value
API (range-based takes_values
)
#198
Milestone
Friday Aug 13, 2021 at 19:28 GMT
Originally opened as clap-rs/clap#2688
Discussed in clap-rs/clap#2676
Originally posted by epage August 10, 2021
Currently, we have
takes_value
multiple_values
min_values
max_values
We then have to clarify how these are related to each other, for example:
(taken from docs.rs, since updated to say
multiple_occurrences
).I had already been brainstorming on this idea when kbknapp mentioned
I think we can simplify this problem down to
takes_values(num: impl clap::IntoRange)
withimpl IntoRange for usize
impl IntoRange for
...each range typeSo you can do
take_values(0)
,take_values(2)
,take_values(1..)
,take_values(0..=1)
bool
, but I think that is making it too magical and isn't as needed.takes_values(1)
being the default.While I was already talking with kbknapp, I brought this up and is thoughts were:
Notes
For the question from kbknapp
I would say occurrences, actually. This would leave room for the two features to compose, like
multiple_occurrences(true).takes_values(2)
. Not a common pattern but I think it speaks to an API when the features compose together in a natural way which this allows.RE Delimiters
I would posit that common cases for multiple values are
0..=1
2
0..
or1..
with a delimiterWe should raise awareness of
require_delimiter
in the docs fortake_values
.Benefits
The text was updated successfully, but these errors were encountered: