-
-
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 default_missing_value_t
, default_value_if_t
, etc
#2813
Comments
As I see it, those methods are all special cases of a pattern that uses a type to generate some code, but why allow only a few special cases not all such patterns? default_value_t basically generates a call to pub struct Arg {
pub fn default_value(self, val: &'help str) -> Self;
} as something like this: arg = Arg::default_value(arg, generate_default_from_type!{T});
It could be implemented by allowing the user to annotate like such: struct Opt {
#[clap(modify_t(my_mod))]
arg: i32,
}
fn my_mod<T: Default + serde::Serialize>(a: Arg) -> Arg {
let val: &'static str = todo!("serialize default T with serde_json, and leak boxed string");
a.default_value(val)
.default_value_if(todo!(), todo!(), todo!())
} Derive crate could generate something like this: arg = my_mod::<T>(arg); It would still be useful to have attributes such as |
I actually would like to generate If you like the above-described solution, I could actually try implementing it and making a pull request |
Let's split that out into its own issue to talk about. This is specifically about providing natively typed magic methods that map to regular methods. |
Also of note: we might want to see how #2683 impacts this issue. |
The order of suffixes allows us to preserve the original builder function name. This is a part of #2813
Please complete the following tasks
Clap Version
v3.0.0-beta.4
Describe your use case
clap_derive
has adefault_value_t
attribute that takes a rust data type, instead of a string, and sets it asdefault_value
on theArg
.However, there are related functions that are missing similar
_t
magic methodsDescribe the solution you'd like
Add magic methods for other raw methods that accept a value corresponding to the field the attribute is applied to
Alternatives, if applicable
No response
Additional Context
No response
The text was updated successfully, but these errors were encountered: