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
Add directory arg support #23
Comments
The orignial motivation of this crate was to handle files, but I think directory support makes. It has some basic support in ClioPath and the clap validaotor already, e.g. you can get clap to validate that a path is a directory that exists like so:
What were you imaginging? A specific type so you could just use #[clap(value_parser)]? |
Nice. Any chance you can provide a sample for how to do that with the "builder" clap pattern? I have everything working except this bit: Arg::new("path").short('p').long("path")
.default_value(WORKING_DIR_PATH.as_os_str())
.value_parser(value_parser!(ClioPath)) error error[E0599]: the method `value_parser` exists for reference `&&&&&&_AutoValueParser<ClioPath>`, but its trait bounds were not satisfied
--> butane_cli/src/main.rs:23:27
|
23 | .value_parser(value_parser!(ClioPath))
| ^^^^^^^^^^^^^^^^^^^^^^^ method cannot be called on `&&&&&&_AutoValueParser<ClioPath>` due to unsatisfied trait bounds
|
::: /home/jayvdb/.cargo/registry/src/index.crates.io-6f17d22bba15001f/clap-4.1.6/src/builder/value_parser.rs:2187:1
|
2187 | pub struct _AutoValueParser<T>(std::marker::PhantomData<T>);
| ------------------------------ doesn't satisfy `_: _ValueParserViaParse` It would be useful to have helpers for a "base directory" arg. i.e. encapsulate the |
You have the right code, you just need to enable the Also if you enable the That said I am not sure that I see the value in I am probably thinking about this too much but it did make me raise #24 as with Here is a full example incase it helps.
|
Turns out there is already clap-rs/clap#4643 "assert_defaults assumes parsers are stateless" |
The other issue that may cause that error is that cargo may be including both clap 3 and clap 4 and clio then implements the clap 3 _AutoValueParser but clap is expecting it to implement the clap 4 _AutoValueParser, in that case I resort to updtaing the Cargo.lock file manullaly. |
Adding feature |
Fixed #24 and added a directory example to the docs. |
Would it make sense to expand this crate to include directory args?
I created a simple
--path
arg at Electron100/butane#130 , and it was not simple to do with builder pattern, and needs to be more complicated to be correct. It should be easier, and aclio
helper could provide it.Then there are variations for whether the directory should exist already, or the user has sufficient permissions to create it.
The text was updated successfully, but these errors were encountered: