use syn::{Attribute, Ident, ItemFn, ItemStruct, PathSegment, spanned::Spanned};
#[derive(Default)]
pub struct Attributes(pub Vec<Attribute>);
#[derive(Debug)]
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 struct TusksParameters {
pub pstruct: ItemStruct,
}
pub struct Tusk {
pub func: ItemFn,
pub is_default: bool
}
pub struct ExternalModule {
pub alias: Ident,
pub item_use: syn::ItemUse,
}
impl std::fmt::Debug for TusksParameters {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("TusksParameters")
.field("name", &self.pstruct.ident.to_string())
.finish()
}
}
impl std::fmt::Debug for Tusk {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("Tusk")
.field("name", &self.func.sig.ident.to_string())
.finish()
}
}
impl std::fmt::Debug for ExternalModule {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("ExternalModule")
.field("alias", &self.alias.to_string())
.field("item_use", &format!("ItemUse at span: {:?}", self.item_use.span()))
.finish()
}
}
impl std::fmt::Debug for Attributes {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("Attributes")
.field("count", &self.0.len())
.field(
"attributes",
&self.0.iter().map(|attr| {
let path_str = attr
.path()
.segments
.iter()
.map(|seg: &PathSegment| seg.ident.to_string())
.collect::<Vec<_>>()
.join("::");
format!("{} at span: {:?}", path_str, attr.span())
}).collect::<Vec<String>>(),
)
.finish()
}
}