From d55f040bbdb73b504108adde83fbc5f5c6557496 Mon Sep 17 00:00:00 2001 From: Ed Page Date: Tue, 14 Dec 2021 10:03:28 -0600 Subject: [PATCH] fix(derive): Set both about/long_about with doc comments 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 #2983 --- clap_derive/src/utils/doc_comments.rs | 5 ++++- tests/derive/doc_comments_help.rs | 7 +++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/clap_derive/src/utils/doc_comments.rs b/clap_derive/src/utils/doc_comments.rs index f0cb9621897..7ac872cf364 100644 --- a/clap_derive/src/utils/doc_comments.rs +++ b/clap_derive/src/utils/doc_comments.rs @@ -61,7 +61,10 @@ pub fn process_doc_comment(lines: Vec, 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)), + ] } } diff --git a/tests/derive/doc_comments_help.rs b/tests/derive/doc_comments_help.rs index c35718b91f2..4b2d22c02e1 100644 --- a/tests/derive/doc_comments_help.rs +++ b/tests/derive/doc_comments_help.rs @@ -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); }