Skip to main content

runi_cli_macros/
lib.rs

1//! Procedural macros for `runi-cli`. The runtime crate stays zero-dep;
2//! this crate uses `syn` and `quote` at compile time only.
3//!
4//! Use via `runi_cli::Command` — this crate is re-exported by `runi-cli`
5//! so downstream users add one dependency, not two.
6
7use proc_macro::TokenStream;
8
9mod command;
10
11/// Derive `runi_cli::Command` for a struct or enum.
12///
13/// On a struct, each field becomes an option or positional argument
14/// depending on its attribute and type. On an enum, each variant becomes
15/// a subcommand (the variant struct is registered on a `Launcher<G>`).
16#[proc_macro_derive(Command, attributes(command, option, argument))]
17pub fn derive_command(input: TokenStream) -> TokenStream {
18    command::derive(input.into())
19        .unwrap_or_else(|e| e.to_compile_error())
20        .into()
21}