config-rs
config-rs copied to clipboard
Command-line configuration
Would you consider adding CLI support? A scenario I'm thinking of would work very nicely if you could override most/all of the config from CLI input, and it seems redundant to use clap to find the config file, get the contents of the config file, and then clobber those values with CLI inputs where they exist.
In the C# world, I'd add the https://www.nuget.org/packages/Microsoft.Extensions.Configuration.CommandLine/ package, which would then allow inputs in a number of forms, which would then override the config file settings depending on precedence.
A close integration with clap would definitely be a neat thing to have.
what are your thoughts on this integration, should it be like multiple --conf key=value parameters passed through the command line which will override the values in the config
If possible, it'd be great to reuse the names of fields in the struct, or allow them to be set via macros, so they can be used directly as flags (e.g. --key=value). Otherwise, yeah, --conf "key=value".
sure will figure out how to do it through macros, still new to rust :) did initial version with multiple --conf parameter, let me know ur thoughts
https://github.com/tanujitghosh/config-rs/blob/issue-64/src/config.rs . - merge_args() https://github.com/tanujitghosh/config-rs/blob/issue-64/tests/file_toml.rs . - test case here
An integration with Clap will be the way to go in my opinion too. Did you start working on that? Otherwise, I might give it a shot.
It seems to me clap integration could be implemented by providing a derive macro allowing a user to convert a struct into a Config value, which could then be merged with other sources in the usual way.
This would also allow the programmer to declare a single static struct with all of the default values, and convert that into the base Config for merger with other sources.
It should be possible to do a poor man's version of this already by implementing Serialize for the struct produced by clap and then deserializing the result into a Config.