-
-
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
Support non-Display types with default_value_t
#4558
Comments
default_value_t
If your default is literally |
AH, thanks @epage! I assume |
Yeah, I've been wanting to do something about this but it appears we don't have an issue for this, so now we do! Most likely this will require deref coercion, like |
this thread was critical for me! the clap docs & guide didn't call out thanks! |
Is it possible to specify a default value that doesn't get passed through a parser? I have something like: #[derive(Parser)]
struct Args {
#[arg(long, value_parser = thing_parser, default_value_t = THING_CONST)]
thing: Thing,
}
fn thing_parser(s: &str) -> Result<Thing, Error> { ... } Unfortunately this takes The example is a bit over-simplified, but basically I've run into situations where I can't implement The workarounds I've used are not pretty. I've tried making wrapper types for |
Within the builder API, the primary value add of defaults is to display them in help which requires For derive users, the value proposition is a little different because someone just might prefer their struct to have With that said, one possible way of solving this is to expand on our auto-detection of
This is somewhat similar to the last point, the user seeing the default should probably be able to pass it in manually. |
Please complete the following tasks
Clap Version
4.0.29
Describe your use case
Currently, there's no way (that I can figure out) to set a default value on a
PathBuf
using derive. You can see a minimal reproducible example here. The specific error is:Describe the solution you'd like
Ideally, either logic to allow for PathBufs to display correctly with the
.display()
call, or a way of suplementing default values let you write a custom display string.Alternatives, if applicable
No response
Additional Context
No response
The text was updated successfully, but these errors were encountered: