-
Is there currently a way to call a function to provide a default value (instead of a static string)? This is in the context of Clap's proc_macro. We have some resolution logic (config file, plus global configuration, plus some environment stuff) for default values, and that would be very useful. For a concrete example, we have a I know there is a |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 3 replies
-
If you're OK with precomputing the default only once per arg, you can use #[structopt(long, default_value = default_function())]
file: PathBuf This will be translated into arg
.long("file")
.default_value(default_function()) In other words, the function will be executed even before the parsing starts. If this function creates a temporary file of sorts, this may be undesirable.
|
Beta Was this translation helpful? Give feedback.
-
I would really like to discourage you from using Better to use |
Beta Was this translation helpful? Give feedback.
-
Here is the link to the hooks issue which should solve this. #1634 |
Beta Was this translation helpful? Give feedback.
Here is the link to the hooks issue which should solve this. #1634