Skip to main content

workflow_terminal_macros/
lib.rs

1//! Procedural macros for the `workflow-terminal` CLI framework, providing
2//! declarative generation of command [`Handler`] implementations and bulk
3//! handler registration.
4use proc_macro::TokenStream;
5mod handlers;
6mod register;
7
8/// Implements the `workflow_terminal::cli::Handler` trait for a given type from
9/// `declare_handler!(<type>, [<verb>,] <help>)`, deriving the command verb from
10/// the type name (kebab-cased) when one is not supplied.
11#[proc_macro]
12pub fn declare_handler(input: TokenStream) -> TokenStream {
13    handlers::declare_handler(input)
14}
15
16/// Derives a `workflow_terminal::cli::Handler` implementation for the annotated
17/// type, taking the command verb and `help` text from `#[verb(..)]` and
18/// `#[help(..)]` attributes and defaulting the verb to the kebab-cased type name.
19#[proc_macro_derive(Handler, attributes(help))]
20pub fn declare_handler_derive(input: TokenStream) -> TokenStream {
21    handlers::declare_handler_derive(input)
22}
23
24/// Registers a list of command handlers with a target from
25/// `register_handlers!(<context>, <target>, [<module names>])`, instantiating
26/// each handler and attaching it to the target's command tree.
27#[proc_macro]
28pub fn register_handlers(input: TokenStream) -> TokenStream {
29    register::register_handlers(input)
30}