Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: make code clean #21

Merged
merged 1 commit into from
Feb 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 20 additions & 21 deletions impl/src/models/fncmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,15 +102,15 @@ impl ToTokens for Fncmd {
// but `main` function with parameters is not legal.
if !attrs.is_empty() {
let __item_fn = quote!(#item).to_string();
let code = quote! {
quote! {
#documentation
#(#attrs)*
#[fncmd(__item_fn=#__item_fn)]
#visibility #asyncness fn main() #return_type {
#body
}
};
code.to_tokens(tokens);
}
.to_tokens(tokens);
return;
}

Expand Down Expand Up @@ -179,32 +179,32 @@ impl ToTokens for Fncmd {
#body
};

let parse = quote! {
use fncmd::clap::Parser;
__fncmd_options::parse()
};

let into_exit_code = quote! {
use fncmd::IntoExitCode;
__fncmd_exec_impl(__fncmd_options).into_exit_code()
};

let exec_body = if !subcmd_cases.is_empty() {
quote! {
let __fncmd_options = __fncmd_options.unwrap_or_else(|| {
use fncmd::clap::Parser;
__fncmd_options::parse()
});
let __fncmd_options = __fncmd_options.unwrap_or_else(|| { #parse });
match __fncmd_options.__fncmd_subcmds {
#(#subcmd_cases)*
_ => {
use fncmd::IntoExitCode;
__fncmd_exec_impl(__fncmd_options).into_exit_code()
}
_ => { #into_exit_code }
}
}
} else {
quote! {
let __fncmd_options = __fncmd_options.unwrap_or_else(|| {
use fncmd::clap::Parser;
__fncmd_options::parse()
});
use fncmd::IntoExitCode;
__fncmd_exec_impl(__fncmd_options).into_exit_code()
let __fncmd_options = __fncmd_options.unwrap_or_else(|| { #parse });
#into_exit_code
}
};

let code = quote! {
quote! {
use fncmd::clap;
#(#subcmd_imports)*

Expand Down Expand Up @@ -232,8 +232,7 @@ impl ToTokens for Fncmd {
fn main() -> impl fncmd::Termination {
__fncmd_exec(None)
}
};

code.to_tokens(tokens);
}
.to_tokens(tokens);
}
}
11 changes: 4 additions & 7 deletions impl/src/models/fncmd_arg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,14 +90,11 @@ impl ToTokens for FncmdArg {
ty,
..
} = self;
let doc = quote! { #documentation };

let code = quote! {
quote! {
#documentation
#(#attributes)*
#doc
#name: #ty
};

code.to_tokens(tokens);
}
.to_tokens(tokens);
}
}