aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--mingling/Cargo.toml3
-rw-r--r--mingling_core/Cargo.toml2
-rw-r--r--mingling_macros/Cargo.toml3
-rw-r--r--mingling_macros/src/dispatcher.rs39
-rw-r--r--mingling_macros/src/lib.rs2
5 files changed, 20 insertions, 29 deletions
diff --git a/mingling/Cargo.toml b/mingling/Cargo.toml
index e52ffe1..7c5d4c5 100644
--- a/mingling/Cargo.toml
+++ b/mingling/Cargo.toml
@@ -18,7 +18,10 @@ mingling = { path = ".", features = ["full"] }
[features]
debug = ["mingling_core/debug"]
async = ["mingling_core/async", "mingling_macros/async"]
+
default = ["mingling_core/default"]
+
+clap_parser = ["mingling_macros/clap_parser"]
full = ["mingling_core/full", "mingling_macros/full", "comp", "parser"]
general_renderer = [
"mingling_core/general_renderer",
diff --git a/mingling_core/Cargo.toml b/mingling_core/Cargo.toml
index 61bee49..b6846e7 100644
--- a/mingling_core/Cargo.toml
+++ b/mingling_core/Cargo.toml
@@ -9,7 +9,9 @@ repository = "https://github.com/catilgrass/mingling"
[features]
default = []
async = []
+
full = ["comp", "general_renderer"]
+
comp = ["dep:just_template"]
debug = ["dep:log", "dep:env_logger"]
general_renderer = [
diff --git a/mingling_macros/Cargo.toml b/mingling_macros/Cargo.toml
index 6def757..1a578a5 100644
--- a/mingling_macros/Cargo.toml
+++ b/mingling_macros/Cargo.toml
@@ -12,7 +12,10 @@ proc-macro = true
[features]
default = []
async = []
+
full = ["comp", "general_renderer"]
+
+clap_parser = []
comp = []
general_renderer = []
diff --git a/mingling_macros/src/dispatcher.rs b/mingling_macros/src/dispatcher.rs
index 6223a81..3ca5d25 100644
--- a/mingling_macros/src/dispatcher.rs
+++ b/mingling_macros/src/dispatcher.rs
@@ -67,7 +67,7 @@ impl Parse for DispatcherChainInput {
// Additionally, the token stream generation patterns are nearly identical between
// the two main functions and could benefit from refactoring.
-pub fn dispatcher_chain(input: TokenStream) -> TokenStream {
+pub fn dispatcher(input: TokenStream) -> TokenStream {
// Parse the input
let dispatcher_input = syn::parse_macro_input!(input as DispatcherChainInput);
@@ -96,46 +96,29 @@ pub fn dispatcher_chain(input: TokenStream) -> TokenStream {
let comp_entry = get_comp_entry(&pack);
- let expanded = if use_default {
- // For default case, use ThisProgram
- quote! {
- #[derive(Debug, Default)]
- pub struct #command_struct;
-
- ::mingling::macros::pack!(ThisProgram, #pack = Vec<String>);
-
- #comp_entry
+ let expanded = {
+ let program_ident = if use_default {
+ Ident::new("ThisProgram", proc_macro2::Span::call_site())
+ } else {
+ group_name.clone()
+ };
- impl ::mingling::Dispatcher<ThisProgram> for #command_struct {
- fn node(&self) -> ::mingling::Node {
- ::mingling::macros::node!(#command_name_str)
- }
- fn begin(&self, args: Vec<String>) -> ::mingling::ChainProcess<ThisProgram> {
- #pack::new(args).to_chain()
- }
- fn clone_dispatcher(&self) -> Box<dyn ::mingling::Dispatcher<ThisProgram>> {
- Box::new(#command_struct)
- }
- }
- }
- } else {
- // For explicit case, use the provided group_name
quote! {
#[derive(Debug, Default)]
pub struct #command_struct;
- ::mingling::macros::pack!(#group_name, #pack = Vec<String>);
+ ::mingling::macros::pack!(#program_ident, #pack = Vec<String>);
#comp_entry
- impl ::mingling::Dispatcher<#group_name> for #command_struct {
+ impl ::mingling::Dispatcher<#program_ident> for #command_struct {
fn node(&self) -> ::mingling::Node {
::mingling::macros::node!(#command_name_str)
}
- fn begin(&self, args: Vec<String>) -> ::mingling::ChainProcess<#group_name> {
+ fn begin(&self, args: Vec<String>) -> ::mingling::ChainProcess<#program_ident> {
#pack::new(args).to_chain()
}
- fn clone_dispatcher(&self) -> Box<dyn ::mingling::Dispatcher<#group_name>> {
+ fn clone_dispatcher(&self) -> Box<dyn ::mingling::Dispatcher<#program_ident>> {
Box::new(#command_struct)
}
}
diff --git a/mingling_macros/src/lib.rs b/mingling_macros/src/lib.rs
index 5ee53a1..5736578 100644
--- a/mingling_macros/src/lib.rs
+++ b/mingling_macros/src/lib.rs
@@ -55,7 +55,7 @@ pub fn pack(input: TokenStream) -> TokenStream {
#[proc_macro]
pub fn dispatcher(input: TokenStream) -> TokenStream {
- dispatcher::dispatcher_chain(input)
+ dispatcher::dispatcher(input)
}
#[proc_macro]