Skip to content

Commit

Permalink
Allow flatten with doc comments
Browse files Browse the repository at this point in the history
  • Loading branch information
CreepySkeleton committed Aug 25, 2020
1 parent 317a816 commit a951958
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 46 deletions.
15 changes: 5 additions & 10 deletions clap_derive/src/attrs.rs
Expand Up @@ -481,12 +481,15 @@ impl Attrs {
"parse attribute is not allowed for flattened entry"
);
}
if res.has_explicit_methods() || res.has_doc_methods() {
if res.has_explicit_methods() {
abort!(
res.kind.span(),
"methods and doc comments are not allowed for flattened entry"
"methods are not allowed for flattened entry"
);
}

// ignore doc comments
res.doc_comment = vec![];
}

Kind::ExternalSubcommand => {
Expand Down Expand Up @@ -695,14 +698,6 @@ impl Attrs {
.iter()
.any(|m| m.name != "about" && m.name != "long_about")
}

pub fn has_doc_methods(&self) -> bool {
!self.doc_comment.is_empty()
|| self
.methods
.iter()
.any(|m| m.name == "about" || m.name == "long_about")
}
}

/// replace all `:` with `, ` when not inside the `<>`
Expand Down
19 changes: 19 additions & 0 deletions clap_derive/tests/flatten.rs
Expand Up @@ -132,3 +132,22 @@ fn merge_subcommands_with_flatten() {
Opt::parse_from(&["test", "command2", "43"])
);
}

#[test]
fn flatten_with_doc_comment() {
#[derive(Clap, Debug)]
struct DaemonOpts {
#[clap(short)]
user: String,
#[clap(short)]
group: String,
}

#[derive(Clap, Debug)]
#[clap(name = "basic")]
struct Opt {
/// A very important doc comment I just can't leave out!
#[clap(flatten)]
opts: DaemonOpts,
}
}
30 changes: 0 additions & 30 deletions clap_derive/tests/ui/flatten_and_doc.rs

This file was deleted.

5 changes: 0 additions & 5 deletions clap_derive/tests/ui/flatten_and_doc.stderr

This file was deleted.

2 changes: 1 addition & 1 deletion clap_derive/tests/ui/flatten_and_methods.stderr
@@ -1,4 +1,4 @@
error: methods and doc comments are not allowed for flattened entry
error: methods are not allowed for flattened entry
--> $DIR/flatten_and_methods.rs:22:19
|
22 | #[clap(short, flatten)]
Expand Down

0 comments on commit a951958

Please sign in to comment.