requires: https://github.com/mehcode/config-rs/pull/379
To allow developers to configure custom config sources from systems.
This PR also replaces config_plugin
attribute macro with ConfigPlugin
derive macro.
All attribute options are still available via ConfigPlugin's builder methods.
App::new()
.add_plugin(
ConfigPlugin::new()
.default_paths(false) // default: true
.env_prefix("APP") // default: ""
.env_separator("___") // default: "__"
.default_from_str(include_str!("config/default.yaml")) // default: include_str!("config/default.toml")
.default_file_format(config::FileFormat::Yaml) // default: Toml
)
.add_startup_system(add_config_source.before(build_config))
.add_system(log_config.after(build_config))
.run();
#[derive(ConfigPlugin, Debug, Deserialize)]
struct Config {
// ...
}
// add custom source to builder
fn add_config_source(mut builder: ResMut<ConfigBuilder<DefaultState>>) {
*builder = builder
.clone()
.add_source(File::with_name("examples/cli/config/config/development"));
}
fn log_config(config: Res<Config>) {
println!("{:#?}", *config);
}