-
-
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
Implement convenient helper methods for PathBufValueParser
to reduce boilerplate
#4074
Comments
Huh, I don't think I ever created an issue for this but I had designed this with click's features in mind. Specifically, we have
Also supporting customization on To allow extra dependencies to be pulled in and for faster iteration, we might start this off in a |
Something I saw that is important to keep in mind for
|
Resolves a few of the use cases outlined in clap-rs#4074.
Resolves a few of the use cases outlined in clap-rs#4074.
Resolves a few of the use cases outlined in clap-rs#4074.
Resolves a few of the use cases outlined in clap-rs#4074.
Resolves a few of the use cases outlined in clap-rs#4074.
IIUC, it's worth checking out https://github.com/aj-bagwell/clio, which does some of these... |
Thanks for letting us know of that! I've created
which I think would bring it to parity with clap |
Thanks for the great ideas and opening the issues. I have implemented most of them. parser/validatorI have added a bunch of validation options to parser/validator There is also
Input
OutputPath
Output
Pull requests to clio are always welcome, or if this looks useful enough to get pulled into clap proper that would be excelent too. |
clap v4.3.6 is released which sugests using clio. I'd love to hear people's thoughts on it over time to decide where to go from here. Personally, I would lean towards this being kept as a separate crate so we have more flexibility regarding the implementation. If anything (and with the author's go ahead), I could see it being renamed to Personally, I'd prefer not to have HTTP support. imo arguments that accept URLs should explicitly opt-in, at minimum. |
Thank you for the official recommendation @epage! I agree that HTTP support should be opt in which is why it is behind a feature that is off by default. For most uses piping via curl is a better choice. I added it because I needed to stream to S3 which needs to be told the content size when starting the upload, also knowing the size of the input turned out to give nicer progress bars. If enough people show interest and want to help work on it then we can look into moving the code into the clap-rs. |
What I mean is it should be opt-in on a per-argument basis rather than on an application level basis with feature flags |
Please complete the following tasks
Clap Version
3.2.17
Describe your use case
Summary
Popular command-line argument parser libraries for other languages implement validation helpers for paths for more convenient and terse CLI construction.
Example
For example, Python's
click
provides aclick.Path
type for validation, with which you can do things like:Why?
This would allow for a reduction of boilerplate for common use-cases (i.e., existing files, existing directories, etc), and ultimately provide a more friendly and convenient "batteries-included" developer experience.
TOCTOU?
The TOCTOU issue will still be present for the validated paths, but in my opinion this enhancement would still allow for a more convenient "fail-fast" approach for CLI applications.
Describe the solution you'd like
Existing Helpers
The existing integer value parsers appear to already provide a
.range(x..y)
helper method to simplify parsing of narrowed integer ranges.This allows for usage such as (as per the tutorial):
Possible Solution
I would like similar helper methods for other types, in this case specifically the
PathBufValueParser
.For example, this could allow usage such as the follows (exact form up for discussion):
Future Scope
There are other less common use cases - such as checking for readability and writability, or checking that a file/directory does not currently exist - that could also be implemented (possibly with more enums, or method chaining?).
For example:
Alternatives, if applicable
No response
Additional Context
No response
The text was updated successfully, but these errors were encountered: