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,
pub value_enums: Vec<ItemEnum>,
}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
value_enums: Vec<ItemEnum>Enum definitions (e.g. #[derive(ValueEnum)]) to re-export in generated cli module
Implementations§
Source§impl TusksModule
impl TusksModule
Source§impl TusksModule
Internal helpers for CLI code generation.
impl TusksModule
Internal helpers for CLI code generation.
Sourcepub fn is_parameters_type(ty: &Type, params_ident: &Ident) -> bool
pub fn is_parameters_type(ty: &Type, params_ident: &Ident) -> bool
Check if a type is a reference to a parameters struct
Source§impl TusksModule
Internal helpers for parameter supplementation.
impl TusksModule
Internal helpers for parameter supplementation.
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
Internal helpers for handle_matches code generation.
impl TusksModule
Internal helpers for handle_matches code generation.
Sourcepub fn build_match_arms_recursive(&self, path: &ModulePath) -> Vec<TokenStream>
pub fn build_match_arms_recursive(&self, path: &ModulePath) -> Vec<TokenStream>
Build match arms recursively with path tracking
pub fn build_no_command_error(path: &ModulePath) -> TokenStream
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: &ModulePath,
) -> TokenStream
pub fn build_function_match_arm( &self, tusk: &Tusk, cli_path: &TokenStream, path: &ModulePath, ) -> TokenStream
Generates a match arm for a command function.
For fn my_func(arg1: String, arg2: i32) this produces:
Some(cli::Commands::my_func { arg1: p1, arg2: p2 }) => {
super::my_func(p1.clone(), p2.clone());
}pub fn build_default_function_match_arm( &self, tusk: &Tusk, path: &ModulePath, is_external_subcommand_case: bool, ) -> TokenStream
pub fn build_external_subcommand_match_arm( &self, tusk: &Tusk, path: &ModulePath, ) -> 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>
Converts bindings to pattern fields [field: p1, field: p2, ...],
filtering out generated fields.
Source§impl TusksModule
impl TusksModule
Sourcepub fn build_submodule_match_arm(
&self,
cli_path: &TokenStream,
path: &ModulePath,
) -> TokenStream
pub fn build_submodule_match_arm( &self, cli_path: &TokenStream, path: &ModulePath, ) -> TokenStream
Generates a match arm for a submodule. The complete generated pattern:
Some(cli::Commands::admin { user: p1, sub }) => {
let super_parameters = ¶meters;
let parameters = super::admin::Parameters { user: p1, super_: super_parameters, .. };
match sub {
// ... nested arms ...
}
}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),
}