Replies: 2 comments
-
|
I would also like to see a solution for this at the crate level. It seems a strange gap in the library that this isn't directly supported. In the interim, I've taken to implementing You can then "iterate" the fields of your struct and use a helper function such as: to parse out the values. Then you just |
Beta Was this translation helpful? Give feedback.
-
|
This is already possible fwiw. You just need to expose your config somehow (I map my figment to a Then I can do, e.g.: #[clap(long, default_value_t = CONFIG.platforms.build.to_string())]
build_platform: String,based on claps rules, this will use the configuration value as the default only when not passed by the user. Then you reference the value exclusive from your cli args in app. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
I want to prioritize CLI parameters over parameters from a config file or the environment but only if the CLI parameters are explicitly set (e.g. not derived via the clap default value).
If I understand correctly, merging with
clapparameters only works if every CLI parameter has a default value.I have the following config struct:
And 2 functions to parse the configuration, with a different order for the config sources:
My general expectation for CLI tools is, that explicitly passed command line parameters overwrite everything else (e.g. parameters from env or config files). If I want this, i have to use the
load_env_firstfunction. But since for this to work, every clap parameter needs a default value, those default values overwrite everything from env and config files, if I place the serialized defaults last.Is it possible to achieve the following behavior using figment, clap and configuration files/environment variables?
Beta Was this translation helpful? Give feedback.
All reactions