-
-
Notifications
You must be signed in to change notification settings - Fork 1k
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
Ranged values for Vec<usize> or any number Vec type like 1-10 or 1..10 #4679
Comments
Providing function would work, but I considered this one of a common use case to get the vector of integers hence thought it might be better to implement from the clap side. But if there is the problem with reducing the overall size for compilation then I don't know. I'm not from CS so not that knowledgeable about that. Maybe making these kind of functions into helper functions that you can include from the clap features might work to keep the main parser lightweight. But again those things are totally outside of my expertise. Main reason I made this issue is because I thought "there should be range feature, if there is delimiter for multiple values". But if you guys are working on keeping those things minimal, then feel free to ignore this. |
If you feel this should be general, I'd recommend starting something like this out in a crate. We can use that go gain interest to gauge if we should bring it into clap proper. |
I made a package but couldn't figure out how to use it as a value parser for clap properly. I'd like it to parse the values into vector, then flatten that vector into the My parser is here: https://github.com/Atreyagaurav/number_range Cargo.toml
So the parser works as expected, with something like this:
Compiling and running:
But trying to use it as
Gives this:
Which seems to me like clap assumes since it's Making it |
Please complete the following tasks
Clap Version
4.1.4
Describe your use case
I have a program that can skip certain lines based on their line numbers. Consider it similar to head command, but instead of just head 5 lines, it can also skip certain lines. I'm made it skip the line numbers provided to it.
For example if I do:
program --skip 1,3,4 file.csv
it'll skip lines 1,3 and 4, withvalue_delimiter = ','
in the clap arg. Problem is if I want to skip a range support 1-5, I have to either make a different argument that takes a number and skips everything larger than or smaller than that number, or make it take a range separately and then parse it into a different variable. A way to just pass the numbers from CLI in the same argument would be perfect.Describe the solution you'd like
The solution I'd like is a feauture in args like "
expand_range
that you can set true" or "range_delimiter
you can give a string" and if it's a Vec number argument (or similar) then it'll expand the range from the input.Just like how
value_delimiter
works. But those two should work in the same argument. For example:1,4-10,15
should be expanded into[1,4,5,6,7,8,9,10,15]
. If it's easy to implement only using rust syntax range..
and..=
works too. But it shouldn't be infinite.Alternatives, if applicable
Once you have the range character like
-
, you just have to split by therange_delimiter
expand the range, and then flatten it.Additional Context
No response
The text was updated successfully, but these errors were encountered: