Skip to content
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

Expose config builder as resource #117

Merged
merged 8 commits into from Oct 13, 2022
Merged

Conversation

JunichiSugiura
Copy link
Member

@JunichiSugiura JunichiSugiura commented Sep 28, 2022

requires: mehcode/config-rs#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);
}

@vercel
Copy link

vercel bot commented Sep 28, 2022

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated
dip ✅ Ready (Inspect) Visit Preview Oct 13, 2022 at 8:13AM (UTC)

@JunichiSugiura JunichiSugiura changed the title PoC to expose config builder as resource Expose config builder as resource Oct 1, 2022
@JunichiSugiura JunichiSugiura marked this pull request as ready for review October 10, 2022 09:19
@JunichiSugiura JunichiSugiura linked an issue Oct 10, 2022 that may be closed by this pull request
2 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Configuration support
1 participant