Skip to content

Feat: support -h to show configurations options #318

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

Open
GabrielePicco opened this issue Mar 6, 2025 · 0 comments · May be fixed by #346
Open

Feat: support -h to show configurations options #318

GabrielePicco opened this issue Mar 6, 2025 · 0 comments · May be fixed by #346
Assignees

Comments

@GabrielePicco
Copy link
Contributor

GabrielePicco commented Mar 6, 2025

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"
@Dodecahedr0x Dodecahedr0x linked a pull request Apr 15, 2025 that will close this issue
@GabrielePicco GabrielePicco self-assigned this Apr 21, 2025
@GabrielePicco GabrielePicco added documentation Improvements or additions to documentation feature and removed documentation Improvements or additions to documentation feature labels Apr 21, 2025
@GabrielePicco GabrielePicco removed their assignment Apr 21, 2025
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 a pull request may close this issue.

3 participants