From 943b8a811bd1c6ba6c88dc4e05ce869afa37ae59 Mon Sep 17 00:00:00 2001 From: CreepySkeleton Date: Wed, 18 Mar 2020 10:05:31 +0300 Subject: [PATCH 1/2] Make external_subcommand work even with one arg --- structopt-derive/src/lib.rs | 2 +- tests/issues.rs | 24 ++++++++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/structopt-derive/src/lib.rs b/structopt-derive/src/lib.rs index 80429f6f..5e494681 100644 --- a/structopt-derive/src/lib.rs +++ b/structopt-derive/src/lib.rs @@ -641,7 +641,7 @@ fn gen_from_subcommand( ::std::option::Option::Some(#name::#var_name( ::std::iter::once(#str_ty::from(external)) .chain( - matches.#values_of("").unwrap().map(#str_ty::from) + matches.#values_of("").into_iter().flatten().map(#str_ty::from) ) .collect::<::std::vec::Vec<_>>() )) diff --git a/tests/issues.rs b/tests/issues.rs index 4f4ec93d..8b4ac4b5 100644 --- a/tests/issues.rs +++ b/tests/issues.rs @@ -91,3 +91,27 @@ fn issue_324() { let help = get_long_help::(); assert!(help.contains("MY_VERSION")); } + +#[test] +fn issue_359() { + #[derive(Debug, PartialEq, StructOpt)] + struct Opt { + #[structopt(subcommand)] + sub: Subcommands, + } + + #[derive(Debug, PartialEq, StructOpt)] + enum Subcommands { + Add, + + #[structopt(external_subcommand)] + Other(Vec), + } + + assert_eq!( + Opt { + sub: Subcommands::Other(vec!["only_one_arg".into()]) + }, + Opt::from_iter(&["test", "only_one_arg"]) + ); +} From 39083dea44a18df2754d6004b4a832a786c28c65 Mon Sep 17 00:00:00 2001 From: CreepySkeleton Date: Wed, 18 Mar 2020 10:29:15 +0300 Subject: [PATCH 2/2] Update .stderr files --- tests/ui/non_existent_attr.stderr | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/ui/non_existent_attr.stderr b/tests/ui/non_existent_attr.stderr index 17bb87f9..99dc781b 100644 --- a/tests/ui/non_existent_attr.stderr +++ b/tests/ui/non_existent_attr.stderr @@ -1,4 +1,4 @@ -error[E0599]: no method named `non_existing_attribute` found for type `clap::args::arg::Arg<'_, '_>` in the current scope +error[E0599]: no method named `non_existing_attribute` found for struct `clap::args::arg::Arg<'_, '_>` in the current scope --> $DIR/non_existent_attr.rs:14:24 | 14 | #[structopt(short, non_existing_attribute = 1)]