Skip to content

Commit

Permalink
Fix #245 (#246)
Browse files Browse the repository at this point in the history
  • Loading branch information
CreepySkeleton authored and TeXitoi committed Sep 1, 2019
1 parent af85383 commit 14937e8
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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)

Expand Down
6 changes: 5 additions & 1 deletion structopt-derive/src/attrs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
}
Expand Down
32 changes: 32 additions & 0 deletions tests/skip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
);
}

0 comments on commit 14937e8

Please sign in to comment.