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
This commit is contained in:
Ed Page 2021-12-14 10:03:28 -06:00
parent 1811f5e7af
commit d55f040bbd
2 changed files with 7 additions and 5 deletions

View file

@ -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)),
]
}
}

View file

@ -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);
}