Skip to content

Commit

Permalink
chore: add passthrough of verbatim_doc_comment attribute to clap
Browse files Browse the repository at this point in the history
  • Loading branch information
dj8yf0μl committed Jan 6, 2025
1 parent e02529d commit 912744d
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 1 deletion.
1 change: 1 addition & 0 deletions examples/struct_with_subargs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ struct Account {
/// than just the headline
#[interactive_clap(long)]
#[interactive_clap(skip_interactive_input)]
#[interactive_clap(verbatim_doc_comment)]
social_db_folder: Option<String>,
/// Sender account
#[interactive_clap(subargs)]
Expand Down
3 changes: 2 additions & 1 deletion interactive-clap-derive/src/derives/interactive_clap/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use proc_macro_error::abort_call_site;
use quote::{quote, ToTokens};
use syn;

use crate::LONG_VEC_MUTLIPLE_OPT;
use crate::{LONG_VEC_MUTLIPLE_OPT, VERBATIM_DOC_COMMENT};

pub(crate) mod methods;

Expand Down Expand Up @@ -47,6 +47,7 @@ pub fn impl_interactive_clap(ast: &syn::DeriveInput) -> TokenStream {
|| group_string.contains("long")
|| (group_string == *"skip")
|| (group_string == *"flatten")
|| (group_string == VERBATIM_DOC_COMMENT)
{
if group_string != LONG_VEC_MUTLIPLE_OPT {
clap_attr_vec.push(group.stream())
Expand Down
5 changes: 5 additions & 0 deletions interactive-clap-derive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ mod tests;
/// implies `#[interactive_clap(skip_interactive_input)]`, as it's not intended for interactive input
pub(crate) const LONG_VEC_MUTLIPLE_OPT: &str = "long_vec_multiple_opt";

/// `#[interactive_clap(...)]` attribute which translates 1-to-1 into
/// `#[clap(verbatim_doc_comment)]`
/// More info on https://docs.rs/clap/4.5.23/clap/_derive/index.html#command-attributes
pub(crate) const VERBATIM_DOC_COMMENT: &str = "verbatim_doc_comment";

#[proc_macro_derive(InteractiveClap, attributes(interactive_clap))]
#[proc_macro_error]
pub fn interactive_clap(input: TokenStream) -> TokenStream {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ pub struct CliArgs {
///
/// a longer paragraph, describing the usage and stuff with second field's
/// awareness of its possible applications
#[clap(verbatim_doc_comment)]
pub second_field: Option<<String as interactive_clap::ToCli>::CliVariant>,
}
impl interactive_clap::ToCli for Args {
Expand Down

0 comments on commit 912744d

Please sign in to comment.