pub struct TusksModule {
pub name: Ident,
pub attrs: Attributes,
pub external_parent: Option<ExternalModule>,
pub parameters: Option<TusksParameters>,
pub tusks: Vec<Tusk>,
pub submodules: Vec<TusksModule>,
pub external_modules: Vec<ExternalModule>,
pub allow_external_subcommands: bool,
}Expand description
Represents a tusks module with all its elements
Fields§
§name: IdentName of the module (e.g. “tasks”, “sub1”)
attrs: Attributes§external_parent: Option<ExternalModule>The parent annotated as pub use … as parent_
parameters: Option<TusksParameters>The Parameters struct (if not existing during parse it will be generated)
tusks: Vec<Tusk>List of all public functions
submodules: Vec<TusksModule>List of all pub sub-modules (recursive)
external_modules: Vec<ExternalModule>List of all external modules (pub use … as …)
allow_external_subcommands: boolif #[command(allow_external_subcommands=true)] is set
Implementations§
Source§impl TusksModule
impl TusksModule
Source§impl TusksModule
impl TusksModule
Source§impl TusksModule
impl TusksModule
Sourcepub fn supplement_parameters(
&mut self,
module: &mut ItemMod,
is_tusks_root: bool,
derive_debug: bool,
) -> Result<()>
pub fn supplement_parameters( &mut self, module: &mut ItemMod, is_tusks_root: bool, derive_debug: bool, ) -> Result<()>
Supplement Parameters structs where missing and add super_ fields
Sourcepub fn extract_lifetime(item_struct: &ItemStruct) -> Result<Lifetime>
pub fn extract_lifetime(item_struct: &ItemStruct) -> Result<Lifetime>
Extract the first lifetime parameter from a struct
Source§impl TusksModule
impl TusksModule
Sourcepub fn build_handle_matches(&self, is_tusks_root: bool) -> TokenStream
pub fn build_handle_matches(&self, is_tusks_root: bool) -> TokenStream
Generate the handle_matches function
Sourcepub fn build_match_arms_recursive(&self, path: &[&str]) -> Vec<TokenStream>
pub fn build_match_arms_recursive(&self, path: &[&str]) -> Vec<TokenStream>
Build match arms recursively with path tracking
pub fn tusk_has_parameters_arg(&self, tusk: &Tusk) -> bool
Source§impl TusksModule
impl TusksModule
Sourcepub fn build_function_match_arm(
&self,
tusk: &Tusk,
cli_path: &TokenStream,
path: &[&str],
) -> TokenStream
pub fn build_function_match_arm( &self, tusk: &Tusk, cli_path: &TokenStream, path: &[&str], ) -> TokenStream
Coordinates the construction of a match arm for a function. Creates all necessary parts and combines them into the final code.
§Examples
For a function fn my_func(arg1: String, arg2: i32) this generates:
Some(cli::Commands::MyFunction { arg1: p1, arg2: p2 }) => {
super::my_func(p1.clone(), p2.clone());
}For a function with parameters fn my_func(params: &Parameters, arg1: String)
this generates:
Some(cli::Commands::MyFunction { arg1: p1 }) => {
super::my_func(¶meters, p1.clone());
}pub fn build_default_function_match_arm( &self, tusk: &Tusk, path: &[&str], is_external_subcommand_case: bool, ) -> TokenStream
pub fn build_external_subcommand_match_arm( &self, tusk: &Tusk, path: &[&str], ) -> TokenStream
Sourcepub fn build_pattern_fields(
&self,
pattern_bindings: &[(Ident, Ident)],
) -> Vec<TokenStream>
pub fn build_pattern_fields( &self, pattern_bindings: &[(Ident, Ident)], ) -> Vec<TokenStream>
Creates the fields for the match arm pattern.
§Examples
For bindings [("arg1", "p1"), ("arg2", "p2")]:
["arg1: p1", "arg2: p2"]Source§impl TusksModule
impl TusksModule
Sourcepub fn build_submodule_match_arm(
&self,
cli_path: &TokenStream,
path: &[&str],
) -> TokenStream
pub fn build_submodule_match_arm( &self, cli_path: &TokenStream, path: &[&str], ) -> TokenStream
Generates a match arm for a submodule in the CLI command enum.
This function creates a pattern match for a submodule, handling:
- Parameter pattern binding generation
- Parameter initialization
- Nested command matching (if submodule has commands)
§Example
Input: submodule “admin” with parameters and commands Output: A match arm like:
Some(Cli::Commands::Admin { user: p1, sub }) => {
let super_parameters = ¶meters;
let parameters = super::admin::Parameters { user: p1, super_: super_parameters };
match sub {
Some(Cli::Commands::User { id }) => { /* handle user command */ }
None => { println!("No function defined for this command!"); }
}
}Source§impl TusksModule
impl TusksModule
pub fn extract_attributes<'a>(&'a self, names: &[&str]) -> Vec<&'a Attribute>
Source§impl TusksModule
impl TusksModule
Sourcepub fn generate_command_attribute(&self) -> TokenStream
pub fn generate_command_attribute(&self) -> TokenStream
Example 1 - Root module of tusks
#[command(name = "tasks")] /// <===== here =====
pub struct Cli {
#[arg(long)]
pub root_param: String,
#[arg(short, long)]
pub verbose: bool,
#[command(subcommand)] /// see generate_command_attribute_for_subcommands
pub sub: Option<Commands>,
}Example 2 - This is a submodule-subcommand:
pub enum Commands {
/// ... other subcommands and submodule-subcommands
#[command(name = "level1")] /// <===== here =====
#[allow(non_camel_case_types)]
level1 {
#[arg(long)]
level1_field: Option<String>,
#[arg(long, default_value = "42")]
level1_number: i32,
#[command(subcommand)] /// see generate_command_attribute_for_subcommands
sub: Option<level1::Commands>,
},
}Sourcepub fn generate_command_attribute_for_subcommands(&self) -> TokenStream
pub fn generate_command_attribute_for_subcommands(&self) -> TokenStream
Example 1 - Root module of tusks
#[command(name = "tasks")] /// see generate_command_attribute
pub struct Cli {
#[arg(long)]
pub root_param: String,
#[arg(short, long)]
pub verbose: bool,
#[command(subcommand)] /// <===== here =====
pub sub: Option<Commands>,
}Example 2 - This is a submodule-subcommand:
pub enum Commands {
/// ... other subcommands and submodule-subcommands
#[command(name = "level1")] /// see generate_command_attribute
#[allow(non_camel_case_types)]
level1 {
#[arg(long)]
level1_field: Option<String>,
#[arg(long, default_value = "42")]
level1_number: i32,
#[command(subcommand)] /// <===== here =====
sub: Option<level1::Commands>,
},
}Sourcepub fn generate_command_attribute_for_external_subcommands(&self) -> TokenStream
pub fn generate_command_attribute_for_external_subcommands(&self) -> TokenStream
Example:
pub enum Commands {
// ... other non-external subcommands ...
#[command(flatten)]
TuskExternalCommands(ExternalCommands),
}