Skip to content

Feat: support -h to show configurations options #318

Open
@GabrielePicco

Description

@GabrielePicco

Description

We currently allow two types of configurations:

  1. A config.toml file
  2. Overrides using environment variables

It is currently quite complex to determine which options are available and how to configure the validator, plus configuration is spread in multiple places in the codebase

Proposed Solution

  • We could have a single defined config, which accept a toml file, and also allows overrides through CLI arguments and ENV variables using clap.
  • We should support the -h flag to list all available options, using Clap or similar

Comment

Clap should support all of this configurations: (from a toml config file, plus args and environment variables override)`.

Naive approach:

use clap::Parser;
#[derive(Clone, Debug, serde::Deserialize, Parser)]
struct F {
    #[arg(long, env)]
    foo: String,
}

fn main() {
    let cfg_file = std::fs::read_to_string("f.toml").ok();
    let cfg = cfg_file.and_then(|cfg_file| toml::from_str::<F>(&cfg_file).ok());
    let cfg = if let Some(mut cfg) = cfg {
        cfg.update_from(std::env::args());
        cfg
    } else {
        F::parse()
    };
    dbg!(cfg);
}
[dependencies]
clap = { version = "4.5.9", features = ["derive", "env"] }
serde = { version = "1.0.204", features = ["derive"] }
toml = "0.8.16"

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions