From 76ed179db3985e8eb79a1267e32cbc0988b99edf Mon Sep 17 00:00:00 2001 From: CreepySkeleton Date: Sat, 21 Dec 2019 20:44:22 +0300 Subject: [PATCH] Propagate #[structopt(no_version)] --- structopt-derive/src/attrs.rs | 13 +++++++++++-- structopt-derive/src/lib.rs | 6 ++++++ tests/author_version_about.rs | 12 ++++++++++++ 3 files changed, 29 insertions(+), 2 deletions(-) diff --git a/structopt-derive/src/attrs.rs b/structopt-derive/src/attrs.rs index ce684a24..1233b55d 100644 --- a/structopt-derive/src/attrs.rs +++ b/structopt-derive/src/attrs.rs @@ -215,9 +215,15 @@ impl Attrs { fn new( default_span: Span, name: Name, + parent_attrs: Option<&Attrs>, casing: Sp, env_casing: Sp, ) -> Self { + let no_version = parent_attrs + .as_ref() + .map(|attrs| attrs.no_version.clone()) + .unwrap_or(None); + Self { name, casing, @@ -228,7 +234,7 @@ impl Attrs { about: None, author: None, version: None, - no_version: None, + no_version, verbatim_doc_comment: None, has_custom_parser: false, @@ -347,10 +353,11 @@ impl Attrs { span: Span, attrs: &[Attribute], name: Name, + parent_attrs: Option<&Attrs>, argument_casing: Sp, env_casing: Sp, ) -> Self { - let mut res = Self::new(span, name, argument_casing, env_casing); + let mut res = Self::new(span, name, parent_attrs, argument_casing, env_casing); res.push_attrs(attrs); res.push_doc_comment(attrs, "about"); @@ -370,6 +377,7 @@ impl Attrs { pub fn from_field( field: &syn::Field, + parent_attrs: Option<&Attrs>, struct_casing: Sp, env_casing: Sp, ) -> Self { @@ -377,6 +385,7 @@ impl Attrs { let mut res = Self::new( field.span(), Name::Derived(name.clone()), + parent_attrs, struct_casing, env_casing, ); diff --git a/structopt-derive/src/lib.rs b/structopt-derive/src/lib.rs index 65f72e22..657f9cae 100644 --- a/structopt-derive/src/lib.rs +++ b/structopt-derive/src/lib.rs @@ -66,6 +66,7 @@ fn gen_augmentation( let mut subcmds = fields.iter().filter_map(|field| { let attrs = Attrs::from_field( field, + Some(parent_attribute), parent_attribute.casing(), parent_attribute.env_casing(), ); @@ -107,6 +108,7 @@ fn gen_augmentation( let args = fields.iter().filter_map(|field| { let attrs = Attrs::from_field( field, + Some(parent_attribute), parent_attribute.casing(), parent_attribute.env_casing(), ); @@ -233,6 +235,7 @@ fn gen_constructor(fields: &Punctuated, parent_attribute: &Attrs) let fields = fields.iter().map(|field| { let attrs = Attrs::from_field( field, + Some(parent_attribute), parent_attribute.casing(), parent_attribute.env_casing(), ); @@ -378,6 +381,7 @@ fn gen_clap(attrs: &[Attribute]) -> GenOutput { Span::call_site(), attrs, Name::Assigned(LitStr::new(&name, Span::call_site())), + None, Sp::call_site(DEFAULT_CASING), Sp::call_site(DEFAULT_ENV_CASING), ); @@ -447,6 +451,7 @@ fn gen_augment_clap_enum( variant.span(), &variant.attrs, Name::Derived(variant.ident.clone()), + Some(parent_attribute), parent_attribute.casing(), parent_attribute.env_casing(), ); @@ -516,6 +521,7 @@ fn gen_from_subcommand( variant.span(), &variant.attrs, Name::Derived(variant.ident.clone()), + Some(parent_attribute), parent_attribute.casing(), parent_attribute.env_casing(), ); diff --git a/tests/author_version_about.rs b/tests/author_version_about.rs index 0c4a4fbb..0f1c8b57 100644 --- a/tests/author_version_about.rs +++ b/tests/author_version_about.rs @@ -44,3 +44,15 @@ fn explicit_version_not_str() { let output = get_long_help::(); assert!(output.contains("custom version")); } + +#[test] +fn no_version_gets_propagated() { + #[derive(StructOpt, PartialEq, Debug)] + #[structopt(no_version)] + enum Action { + Move, + } + + let output = get_subcommand_long_help::("move"); + assert_eq!(output.lines().next(), Some("test-move ")); +}