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

flatten with default raise error #15

Open
junnplus opened this issue Dec 6, 2021 · 0 comments
Open

flatten with default raise error #15

junnplus opened this issue Dec 6, 2021 · 0 comments

Comments

@junnplus
Copy link

junnplus commented Dec 6, 2021

since #7 , flatten is very useful, but i found follow code will raise error.

use serde_derive::Deserialize;
use structopt::StructOpt;
use structopt_toml::StructOptToml;

#[derive(Debug, Deserialize, StructOpt, StructOptToml)]
#[serde(default)]
struct Outer {
    #[structopt(long = "one", default_value = "1")]
    one: u32,
    #[structopt(flatten)]
    two: Inner,
}

#[derive(Debug, Deserialize, StructOpt, StructOptToml)]
#[serde(default)]
struct Inner {
    #[structopt(long = "three", default_value = "1")]
    three: u32,
    #[structopt(long = "four", default_value = "1")]
    four: u32,
}

fn main() {
    let toml_str = r#"
        one = 2
        two.three = 2
        two.four = 2
    "#;
    let test = Outer::from_args_with_toml(toml_str).unwrap();
    println!("{:?}", test);
}
[N] ❯ cargo run -- --one=3
   Compiling struct-default v0.1.0 (/private/tmp/struct-default)
    Finished dev [unoptimized + debuginfo] target(s) in 0.37s
     Running `target/debug/struct-default --one=3`
error: Found argument '--one' which wasn't expected, or isn't valid in this context
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

1 participant