cmdkit-macros
Procedural macros for generating cmdkit command strategies from plain Rust functions.
What It Does
This crate provides one attribute macro:
#[strategy]
It transforms a free function into a concrete type that implements cmdkit::CommandStrategy.
Given a function like create_directory, the macro generates:
- A strategy type named
CreateDirectory - A constructor
CreateDirectory::new() - A helper factory function
create_directory_strategy() - An
impl cmdkit::CommandStrategywithexecute(...)
Installation
Add to your Cargo.toml:
[]
= "0.2.0"
= "0.2.2"
Quick Example
use ;
use strategy;
Required Function Signature
A function annotated with #[strategy] must:
- Be a free function (not a method).
- Not be
async. - Accept exactly these three parameters in this order:
ctx: ExecutionContextarguments: InvocationArgs
- Return
Result<(), cmdkit::StrategyError>.
Example accepted shape:
Naming Rules
The generated type name is UpperCamelCase from the function name.
simple_cli_strategy->SimpleCliStrategycreate_directory->CreateDirectory
Macro Expansion Summary
For:
The macro generates equivalents of:
;
Development
Run tests:
License
This project is licensed under Apache-2.0. See LICENSE for details.later