Skip to content

Commit f28876d

Browse files
smoqadamepage
authored andcommitted
feat: Use long help for PossibleValue
1 parent ae8b514 commit f28876d

File tree

2 files changed

+22
-7
lines changed

2 files changed

+22
-7
lines changed

clap_derive/src/item.rs

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -901,13 +901,26 @@ impl Item {
901901
let (short_help, long_help) =
902902
format_doc_comment(&lines, !self.verbatim_doc_comment, self.force_long_help);
903903
let short_name = format_ident!("{short_name}");
904-
let short = Method::new(
905-
short_name,
906-
short_help
907-
.map(|h| quote!(#h))
908-
.unwrap_or_else(|| quote!(None)),
909-
);
910-
self.doc_comment.push(short);
904+
905+
let is_value_kind = matches!(self.kind.get(), Kind::Value);
906+
let short_method = if is_value_kind && cfg!(feature = "unstable-v5") {
907+
Method::new(
908+
short_name,
909+
long_help
910+
.clone()
911+
.or(short_help)
912+
.map(|h| quote!(#h))
913+
.unwrap_or_else(|| quote!(None)),
914+
)
915+
} else {
916+
Method::new(
917+
short_name,
918+
short_help
919+
.map(|h| quote!(#h))
920+
.unwrap_or_else(|| quote!(None)),
921+
)
922+
};
923+
self.doc_comment.push(short_method);
911924
if let Some(long_name) = long_name {
912925
let long_name = format_ident!("{long_name}");
913926
let long = Method::new(

tests/derive/doc_comments_help.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,8 @@ Arguments:
352352
<X>
353353
Possible values:
354354
- bar: Doc comment summary
355+
356+
The doc comment body is not ignored
355357
356358
Options:
357359
-h, --help

0 commit comments

Comments
 (0)