You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Jan 1, 2022. It is now read-only.
Comment by marjakm Thursday Nov 04, 2021 at 16:00 GMT
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?
generate_default_from_type is a special macro in generator, adding default_missing_value_t support would mean creating a similar macro that also takes the type T. Why only allow this pattern for macros defined in the code generator, why not allow the user of the library to provide the macro (or maybe function) and generate code that provides the type to the user-defined macro (or function).
It could be implemented by allowing the user to annotate like such:
structOpt{#[clap(modify_t(my_mod))]arg:i32,}fnmy_mod<T:Default + serde::Serialize>(a:Arg) -> Arg{let val:&'staticstr = 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 default_value_t and default_missing_value_t, but they could be implemented via having the macros defined as functions somewhere and converting default_missing_value_t to modify_t(generate_default_from_type).
Comment by marjakm Thursday Nov 04, 2021 at 16:06 GMT
I actually would like to generate Arg::about calls in just this way - the arg parses Option<ComplexStruct> via json, the default value should be the empty string, but I'd like to generate an example json in the about.
If you like the above-described solution, I could actually try implementing it and making a pull request
Tuesday Oct 05, 2021 at 14:20 GMT
Originally opened as clap-rs/clap#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: