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/src/build/app/mod.rs b/src/build/app/mod.rs index 32dc75a37a7..22136f7a4c4 100644 --- a/src/build/app/mod.rs +++ b/src/build/app/mod.rs @@ -896,8 +896,8 @@ impl<'help> App<'help> { /// .about("Does really amazing things for great people") /// # ; /// ``` - pub fn about>(mut self, about: S) -> Self { - self.about = Some(about.into()); + pub fn about>>(mut self, about: O) -> Self { + self.about = about.into(); self } @@ -920,8 +920,8 @@ impl<'help> App<'help> { /// # ; /// ``` /// [`App::about`]: App::about() - pub fn long_about>(mut self, about: S) -> Self { - self.long_about = Some(about.into()); + pub fn long_about>>(mut self, long_about: O) -> Self { + self.long_about = long_about.into(); self } diff --git a/src/build/arg/mod.rs b/src/build/arg/mod.rs index 539ec685b04..ff9d05ed7ae 100644 --- a/src/build/arg/mod.rs +++ b/src/build/arg/mod.rs @@ -2712,8 +2712,8 @@ impl<'help> Arg<'help> { /// ``` /// [`Arg::long_help`]: Arg::long_help() #[inline] - pub fn help(mut self, h: &'help str) -> Self { - self.help = Some(h); + pub fn help(mut self, h: impl Into>) -> Self { + self.help = h.into(); self } @@ -2773,8 +2773,8 @@ impl<'help> Arg<'help> { /// ``` /// [`Arg::help`]: Arg::help() #[inline] - pub fn long_help(mut self, h: &'help str) -> Self { - self.long_help = Some(h); + pub fn long_help(mut self, h: impl Into>) -> Self { + self.long_help = h.into(); self } diff --git a/tests/derive/doc_comments_help.rs b/tests/derive/doc_comments_help.rs index 000b98e5c6a..4b2d22c02e1 100644 --- a/tests/derive/doc_comments_help.rs +++ b/tests/derive/doc_comments_help.rs @@ -14,7 +14,7 @@ use crate::utils; -use clap::{ArgEnum, Parser}; +use clap::{ArgEnum, IntoApp, Parser}; #[test] fn doc_comments() { @@ -214,3 +214,27 @@ fn argenum_multiline_doc_comment() { Bar, } } + +#[test] +fn doc_comment_about_handles_both_abouts() { + /// Opts doc comment summary + #[derive(Parser, Debug)] + pub struct Opts { + #[clap(subcommand)] + pub cmd: Sub, + } + + /// Sub doc comment summary + /// + /// Sub doc comment body + #[derive(Parser, PartialEq, Eq, Debug)] + pub enum Sub { + Compress { output: String }, + } + + let app = Opts::into_app(); + assert_eq!(app.get_about(), Some("Opts doc comment summary")); + // 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); +}