Skip to content

Commit

Permalink
fix: add compliance with clap_derive #15
Browse files Browse the repository at this point in the history
Signed-off-by: Benjamin Coenen <[email protected]>
  • Loading branch information
bnjjj committed May 15, 2022
1 parent b81a0aa commit c774c85
Show file tree
Hide file tree
Showing 3 changed files with 1,145 additions and 17 deletions.
6 changes: 5 additions & 1 deletion config-derive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ pub fn config(_attrs: TokenStream, item: TokenStream) -> TokenStream {
Some(attr_ident) if attr_ident == "serde" => {
attr.parse_args::<AssignAttrs>().is_err()
}
Some(attr_ident) if attr_ident == "clap" => false,
Some(attr_ident) if attr_ident == "doc" => {
let doc = match attr.parse_meta() {
Ok(Meta::NameValue(ref nv)) if nv.path.is_ident("doc") => {
Expand Down Expand Up @@ -92,7 +93,10 @@ pub fn config(_attrs: TokenStream, item: TokenStream) -> TokenStream {
let struct_vis = strukt.vis.clone();
let struct_gen = strukt.generics.clone();
let struct_where = strukt.generics.where_clause.clone();
let struct_attrs = strukt.attrs.clone();
let struct_attrs =
strukt.attrs.clone().into_iter().filter(
|attr| matches!(attr.path.get_ident(), Some(attr_ident) if attr_ident == "serde"),
);
let opt_struct_name = Ident::new(format!("Opt{}", struct_name).as_str(), Span::call_site());

let opt_struct = quote! {
Expand Down
21 changes: 5 additions & 16 deletions twelf/examples/clap_derive.rs
Original file line number Diff line number Diff line change
@@ -1,30 +1,19 @@
#![allow(dead_code)]

use clap::{CommandFactory, Parser};
use clap_rs as clap;
use clap::{Parser, Subcommand, CommandFactory};
use twelf::{config, Layer};

#[config]
#[derive(Parser, Debug)]
#[clap(author, version, about, long_about = None)]
struct Config {
#[clap(
long,
help = "Documentation inside clap, to specifiy db_host",
)]
#[clap(long, help = "Documentation inside clap, to specifiy db_host")]
db_host: String,
#[clap(
long,
short,
help = "The number of threads",
)]
#[clap(required = false)]
#[clap(long, short, help = "The number of threads")]
#[clap(required = false, default_value_t = 55)]
threads: usize,
#[clap(
long,
short,
help = "Put in verbose mode",
)]
#[clap(long, short, help = "Put in verbose mode")]
verbose: bool,
}

Expand Down
Loading

0 comments on commit c774c85

Please sign in to comment.