structopt-toml icon indicating copy to clipboard operation
structopt-toml copied to clipboard

flatten with default raise error

Open junnplus opened this issue 4 years ago • 0 comments

since https://github.com/dalance/structopt-toml/pull/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

junnplus avatar Dec 06 '21 09:12 junnplus