Skip to content

Commit

Permalink
fix(derive): Set both about/long_about with doc comments
Browse files Browse the repository at this point in the history
The main care about is that when we override a `flatten` / `subcommand`
doc comment in a parent container, that we make sure we take nothing
from the child container, rather than implicitly taking one `about` ut
not `long_about`.

To do this, and to play the most safe with long help detection, we reset
`long_about` to default when there is no doc comment body to use for
`long_about`.

Fixes clap-rs#2983
  • Loading branch information
epage committed Dec 14, 2021
1 parent 1811f5e commit d55f040
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
5 changes: 4 additions & 1 deletion clap_derive/src/utils/doc_comments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,10 @@ pub fn process_doc_comment(lines: Vec<String>, name: &str, preprocess: bool) ->
lines.join("\n")
};

vec![Method::new(short_name, quote!(#short))]
vec![
Method::new(short_name, quote!(#short)),
Method::new(long_name, quote!(None)),
]
}
}

Expand Down
7 changes: 3 additions & 4 deletions tests/derive/doc_comments_help.rs
Original file line number Diff line number Diff line change
Expand Up @@ -234,8 +234,7 @@ fn doc_comment_about_handles_both_abouts() {

let app = Opts::into_app();
assert_eq!(app.get_about(), Some("Opts doc comment summary"));
assert_eq!(
app.get_long_about(),
Some("Sub doc comment summary\n\nSub doc comment body")
);
// clap will fallback to `about` on `None`. The main care about is not providing a `Sub` doc
// comment.
assert_eq!(app.get_long_about(), None);
}

0 comments on commit d55f040

Please sign in to comment.