-
Notifications
You must be signed in to change notification settings - Fork 31
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
Override values from configuration from CLI #81
Comments
Have you tried using I'm not really sure what you're trying to achieve exactly. That way you've written it, you're overriding everything from the TOML file with the result of |
Yes
Yes, this is what I trying to do. But the problem is that it overrides all values from TOML with CLI. I trying to override only ones that is specified by user. |
Using join for the second invocation would mean you keep values specified in the TOML file even when they're present in the values resulting from
The "trick" is to not serialize default values and to instead use serde's defaults or a default provider on deserialization. Concretely, this means using the |
No, I trying to do the opposite - let user override some values from TOML with some values from CLI. |
What do you mean? If I'm not mistaken, the mechanism I described above accomplishes what you're after without any special changes. You could also develop a special Provider, of course. In any case, it looks like we're all set here, so I'm closing this out. |
Sorry, I misread you. I thought that you thinking that I talking about CLI -> TOML instead of TOML -> CLI. |
I don't think it makes sense to have library-specific providers here, but you can write your own provider if you'd like! You can even release it on crates.io, and assuming it's nicely documented, we can link to it from our docs. |
Makes sense, but don't you have |
Those are formats, not libraries. We could easily swap out the underlying dependencies for others if needed without any changes to our API. We don't expose In any case, I'm not sure what such an integration would look like. |
Fair point.
I wouldn't say that it's easy. The workaround is tricky and involves a lot of boilerplate.
I will try and let you know. |
I was able to put together a proof of concept for this here: https://github.com/Notgnoshi/serdoc I don't really like having to duplicate the Please let us know if you find a better / more generic method!! |
I trying to write an application that reads config and user can override values from it using CLI:
But the problem is that
Config::parse()
requires to set all values. And If I usearg(..., default_value = "...")
it will override values from config.Config::command().get_matches();
allows me to skip specifying edition in CLI (thanks torequired = false
), but I can't passArgMatches
struct to Figment.The text was updated successfully, but these errors were encountered: