From 14937e8b8961bf08cc1732f4eb9bcda111a5f58b Mon Sep 17 00:00:00 2001 From: CreepySkeleton Date: Sun, 1 Sep 2019 22:16:08 +0300 Subject: [PATCH] Fix #245 (#246) --- CHANGELOG.md | 1 + structopt-derive/src/attrs.rs | 6 +++++- tests/skip.rs | 32 ++++++++++++++++++++++++++++++++ 3 files changed, 38 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 69d8ae6b..72b27525 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,6 @@ # v0.3.1 (2019-08-31) * Fix error messages ([#241](https://github.com/TeXitoi/structopt/issues/241)) +* Fix "`skip` plus long doc comment" bug ([#245](https://github.com/TeXitoi/structopt/issues/245)) # v0.3.0 (2019-08-30) diff --git a/structopt-derive/src/attrs.rs b/structopt-derive/src/attrs.rs index 0d2e3683..f390e0e1 100644 --- a/structopt-derive/src/attrs.rs +++ b/structopt-derive/src/attrs.rs @@ -484,7 +484,11 @@ impl Attrs { res.kind = Sp::new(Kind::Subcommand(ty), res.kind.span()); } Kind::Skip => { - if let Some(m) = res.methods.iter().find(|m| m.name != "help") { + if let Some(m) = res + .methods + .iter() + .find(|m| m.name != "help" && m.name != "long_help") + { span_error!(m.name.span(), "methods are not allowed for skipped fields"); } } diff --git a/tests/skip.rs b/tests/skip.rs index d1a0cb85..4943a519 100644 --- a/tests/skip.rs +++ b/tests/skip.rs @@ -92,3 +92,35 @@ fn skip_enum() { } ); } + +#[test] +fn skip_help_doc_comments() { + #[derive(StructOpt, Debug, PartialEq)] + #[structopt(name = "a")] + pub struct Opt { + #[structopt(skip, help = "internal_stuff")] + a: u32, + + #[structopt(skip, long_help = "internal_stuff\ndo not touch")] + b: u32, + + /// Not meant to be used by clap. + /// + /// I want a default here. + #[structopt(skip)] + c: u32, + + #[structopt(short, parse(try_from_str))] + n: u32, + } + + assert_eq!( + Opt::from_iter(&["test", "-n", "10"]), + Opt { + n: 10, + a: 0, + b: 0, + c: 0, + } + ); +}