clap-rs / clap

A full featured, fast Command Line Argument Parser for Rust
docs.rs/clap
Apache License 2.0
13.64k stars 1.02k forks source link

add toml support, like env support #5559

Closed RaphaelDarley closed 3 days ago

RaphaelDarley commented 3 days ago

Please complete the following tasks

Clap Version

4.5.8

Describe your use case

creating a cli tool to run a server which could allow configuration via environment variables or toml

Describe the solution you'd like

a toml features which allows a toml key to be specified in the arg macro:

#[derive(Parser)]
pub struct Cli {
    #[arg(env = "FOO", toml = "foo")]
    foo: String
}

I think by default the priority should be passed argument, env, toml, default. though this should be configureable

Alternatives, if applicable

the main alternative is to manually parse a toml file, the problem with this that that it is difficult to differentiate env or passed values from clap and the default

Additional Context

If this is a feature that there is support for I'd love to implement it

epage commented 3 days ago

We're still trying to figure out what the needs are for layered config which is being discussed at https://github.com/clap-rs/clap/discussions/2763. Closing in favor of that.