Skip to main content

cli_ui_derive/
lib.rs

1//! Proc-macro implementation for `cli-ui`.
2//!
3//! This crate is an implementation detail — use `cli-ui` directly.
4
5use proc_macro::TokenStream;
6use syn::{parse_macro_input, DeriveInput};
7
8mod attrs;
9mod codegen_command;
10mod codegen_options;
11
12/// Derive typed argument parsing for a struct.
13///
14/// See the `cli-ui` crate documentation for full usage and attribute reference.
15#[proc_macro_derive(CliOptions, attributes(cli, arg))]
16pub fn derive_cli_options(input: TokenStream) -> TokenStream {
17    let input = parse_macro_input!(input as DeriveInput);
18    codegen_options::impl_cli_options(&input)
19        .unwrap_or_else(|e| e.to_compile_error())
20        .into()
21}
22
23/// Derive typed subcommand dispatch for an enum.
24///
25/// See the `cli-ui` crate documentation for full usage and attribute reference.
26#[proc_macro_derive(CliCommand, attributes(cli))]
27pub fn derive_cli_command(input: TokenStream) -> TokenStream {
28    let input = parse_macro_input!(input as DeriveInput);
29    codegen_command::impl_cli_command(&input)
30        .unwrap_or_else(|e| e.to_compile_error())
31        .into()
32}