diff --git a/CHANGELOG.md b/CHANGELOG.md index 003271ec..669cbdb2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,16 +1,23 @@ -# NEXT +# v0.2.8 (2018-04-28) * Add `StructOpt::from_iter_safe()`, which returns an `Error` instead of killing the program when it fails to parse, or parses one of the short-circuiting flags. ([#98](https://github.com/TeXitoi/structopt/pull/98) by [@quodlibetor](https://github.com/quodlibetor)) - -* Allow users to enable `clap` features independently. +* Allow users to enable `clap` features independently by + [@Kerollmops](https://github.com/Kerollmops) +* Fix a bug when flattening an enum + ([#103](https://github.com/TeXitoi/structopt/pull/103) by + [@TeXitoi](https://github.com/TeXitoi) # v0.2.7 (2018-04-12) -* Add flattening, the insertion of options of another StructOpt struct into another ([#92](https://github.com/TeXitoi/structopt/pull/92)) by [@birkenfeld](https://github.com/birkenfeld) -* Fail compilation when using `default_value` or `required` with `Option` ([#88](https://github.com/TeXitoi/structopt/pull/88)) by [@Kerollmops](https://github.com/Kerollmops) +* Add flattening, the insertion of options of another StructOpt struct + into another ([#92](https://github.com/TeXitoi/structopt/pull/92)) + by [@birkenfeld](https://github.com/birkenfeld) +* Fail compilation when using `default_value` or `required` with + `Option` ([#88](https://github.com/TeXitoi/structopt/pull/88)) by + [@Kerollmops](https://github.com/Kerollmops) # v0.2.6 (2018-03-31) diff --git a/Cargo.toml b/Cargo.toml index 34ca521c..3002e914 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "structopt" -version = "0.2.7" +version = "0.2.8" authors = ["Guillaume Pinot "] description = "Parse command line argument by defining a struct." documentation = "https://docs.rs/structopt" @@ -27,6 +27,6 @@ travis-ci = { repository = "TeXitoi/structopt" } [dependencies] clap = { version = "2.20", default-features = false } -structopt-derive = { path = "structopt-derive", version = "0.2.7" } +structopt-derive = { path = "structopt-derive", version = "0.2.8" } [workspace] diff --git a/structopt-derive/Cargo.toml b/structopt-derive/Cargo.toml index fcfd226d..33add54f 100644 --- a/structopt-derive/Cargo.toml +++ b/structopt-derive/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "structopt-derive" -version = "0.2.7" +version = "0.2.8" authors = ["Guillaume Pinot "] description = "Parse command line argument by defining a struct, derive crate." documentation = "https://docs.rs/structopt-derive" diff --git a/structopt-derive/src/lib.rs b/structopt-derive/src/lib.rs index 352244fe..0db52cb2 100644 --- a/structopt-derive/src/lib.rs +++ b/structopt-derive/src/lib.rs @@ -90,7 +90,14 @@ fn gen_augmentation(fields: &Punctuated, app_var: &Ident) -> quote Kind::Subcommand(_) => None, Kind::FlattenStruct => { let ty = &field.ty; - Some(quote! { let #app_var = <#ty>::augment_clap(#app_var); }) + Some(quote! { + let #app_var = <#ty>::augment_clap(#app_var); + let #app_var = if <#ty>::is_subcommand() { + #app_var.setting(::structopt::clap::AppSettings::SubcommandRequiredElseHelp) + } else { + #app_var + }; + }) } Kind::Arg(ty) => { let convert_type = match ty { diff --git a/tests/subcommands.rs b/tests/subcommands.rs index abae28a8..c3f18d6a 100644 --- a/tests/subcommands.rs +++ b/tests/subcommands.rs @@ -160,3 +160,20 @@ fn enum_in_enum_subsubcommand() { let result = Opt::from_iter(&["test", "daemon", "start"]); assert_eq!(Opt::Daemon(DaemonCommand::Start), result); } + +#[test] +fn flatten_enum() { + #[derive(StructOpt, Debug, PartialEq)] + struct Opt { + #[structopt(flatten)] + sub_cmd: SubCmd, + } + #[derive(StructOpt, Debug, PartialEq)] + enum SubCmd { + Foo, + Bar, + } + + assert!(Opt::from_iter_safe(&["test"]).is_err()); + assert_eq!(Opt::from_iter(&["test", "Foo"]), Opt { sub_cmd: SubCmd::Foo }); +}