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

Incorrect behavior with struct flattening #35

Open
Shatur opened this issue Sep 8, 2023 · 1 comment
Open

Incorrect behavior with struct flattening #35

Shatur opened this issue Sep 8, 2023 · 1 comment

Comments

@Shatur
Copy link

Shatur commented Sep 8, 2023

Let's consider the following test:

#[test]
fn mixed_clap_flatten_defaults() {
    #[config]
    #[derive(Parser, Debug, Default)]
    #[clap(author, version, about, long_about = None)]
    struct Conf {
        #[clap(flatten)]
        package: Package,
    }

    #[derive(Args, Default, Debug, serde::Serialize, serde::Deserialize)]
    struct Package {
        #[clap(long, required = false)]
        edition: String,
    }

    let matches = Conf::command().get_matches_from(&["test", "--edition=2000"]);

    let prio = vec![Layer::Toml("Cargo.toml".into()), Layer::Clap(matches)];
    let config = Conf::with_layers(&prio).unwrap();

    assert_eq!(config.package.edition, "2000");
}

It panics at assert_eq!(config.package.edition, "2000");. I would expect CLI to override the value from file. But it prints 2021 because due to #[clap(flatten)] it incorrectly merges values from clap.

@0xForerunner
Copy link

+1 on this issue! It' a blocker for me to use this lib unfortunately.

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

No branches or pull requests

2 participants