mirror of
https://github.com/clap-rs/clap
synced 2025-03-04 23:37:32 +00:00
fix ArgEnum multiline doc comment
This commit is contained in:
parent
fe29af7a63
commit
cba7ba5369
4 changed files with 28 additions and 6 deletions
|
@ -794,11 +794,22 @@ impl Attrs {
|
|||
}
|
||||
|
||||
/// generate methods on top of a field
|
||||
pub fn field_methods(&self) -> proc_macro2::TokenStream {
|
||||
pub fn field_methods(&self, supports_long_about: bool) -> proc_macro2::TokenStream {
|
||||
let methods = &self.methods;
|
||||
let doc_comment = &self.doc_comment;
|
||||
let help_heading = self.help_heading.as_ref().into_iter();
|
||||
quote!( #(#doc_comment)* #(#help_heading)* #(#methods)* )
|
||||
match supports_long_about {
|
||||
true => {
|
||||
let doc_comment = &self.doc_comment;
|
||||
quote!( #(#doc_comment)* #(#help_heading)* #(#methods)* )
|
||||
}
|
||||
false => {
|
||||
let doc_comment = self
|
||||
.doc_comment
|
||||
.iter()
|
||||
.filter(|mth| mth.name != "long_about");
|
||||
quote!( #(#doc_comment)* #(#help_heading)* #(#methods)* )
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn cased_name(&self) -> TokenStream {
|
||||
|
|
|
@ -85,7 +85,7 @@ fn lits(
|
|||
if let Kind::Skip(_) = &*attrs.kind() {
|
||||
None
|
||||
} else {
|
||||
let fields = attrs.field_methods();
|
||||
let fields = attrs.field_methods(false);
|
||||
let name = attrs.cased_name();
|
||||
Some((
|
||||
quote! {
|
||||
|
|
|
@ -347,7 +347,7 @@ pub fn gen_augment(
|
|||
};
|
||||
|
||||
let name = attrs.cased_name();
|
||||
let methods = attrs.field_methods();
|
||||
let methods = attrs.field_methods(true);
|
||||
|
||||
Some(quote_spanned! { field.span()=>
|
||||
let #app_var = #app_var.arg(
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
|
||||
mod utils;
|
||||
|
||||
use clap::Parser;
|
||||
use clap::{ArgEnum, Parser};
|
||||
use utils::*;
|
||||
|
||||
#[test]
|
||||
|
@ -204,3 +204,14 @@ fn multiline_separates_default() {
|
|||
let help = get_help::<App>();
|
||||
assert!(help.contains("Multiline [default"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn argenum_multiline_doc_comment() {
|
||||
#[derive(ArgEnum, Clone)]
|
||||
enum LoremIpsum {
|
||||
/// Multiline
|
||||
///
|
||||
/// Doc comment
|
||||
Bar,
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue