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

Re-thinking: Config source: clap #328

Closed
Tracked by #376
matthiasbeyer opened this issue Apr 23, 2022 · 5 comments
Closed
Tracked by #376

Re-thinking: Config source: clap #328

matthiasbeyer opened this issue Apr 23, 2022 · 5 comments

Comments

@matthiasbeyer
Copy link
Member

Do we want to support clap as a source of configuration?


This is of lower importance. First we must decide on #323

@Xuanwo
Copy link
Contributor

Xuanwo commented Apr 24, 2022

I built a lib serfig which powered by serde-bridge to make it possible.

The real use-case:

pub fn load() -> Result<Self> {
    let arg_conf: Self = Config::parse();

    let mut builder: serfig::Builder<Self> = serfig::Builder::default();

    // Load from config file first.
    {
        let config_file = if !arg_conf.config_file.is_empty() {
            arg_conf.config_file.clone()
        } else if let Ok(path) = env::var("CONFIG_FILE") {
            path
        } else {
            "".to_string()
        };

        builder = builder.collect(from_file(Toml, &config_file));
    }

    // Then, load from env.
    builder = builder.collect(from_env());

    // Finally, load from args.
    builder = builder.collect(from_self(arg_conf));

    Ok(builder.build()?)
}

Hoping these can help config-rs a bit!

@dnaka91
Copy link

dnaka91 commented May 1, 2022

Native support for clap would be great. In Trunk, we currently have config file + env file and lastly clap as input for settings. Most of the file settings can be overriden by clap as well.

At the moment we do all this merging by hand, but config does pretty much the same as we do, so we might want to move to it in the near future. This would be a great convenience to have.

@Sn0rt
Copy link

Sn0rt commented Jul 16, 2024

I also agree with this demand, and this demand still has great prospects.

@epage epage removed the re-think label Oct 23, 2024
@0xForerunner
Copy link

+1 on this feature!

@epage
Copy link
Contributor

epage commented Nov 21, 2024

Closing this in favor of #64 so we don't split the conversation any further.

@epage epage closed this as not planned Won't fix, can't repro, duplicate, stale Nov 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants