clap_reverse_derive 0.1.1

Internal subcrate for `clap_reverse` crate
Documentation
/// Derive macro to automatically implement [`AsCommand`] for a struct, allowing it
/// to be converted into a [`std::process::Command`]. If `display` is specified
/// in struct attributes, it also implements [`std::fmt::Display`] to show the equivalent
/// command line.
///
/// # Struct-Level Attributes
/// - `display` – generate a `Display` implementation showing the command
/// - `binary` – set the command executable (required if no field has `binary`)
/// - `prefix` – default prefix for arguments (default `"--"`)
/// - `delimiter` – default delimiter between argument name and value (default `" "`)
///
/// # Field-Level Attributes
/// - `prefix` – override struct-level prefix for this field
/// - `name` – override the argument name (defaults to the Rust field name)
/// - `delimiter` – override struct-level delimiter for this field
/// - `binary` – mark this field as the command executable (only one allowed)
/// - `transparent` – include the field value only, omit the argument name
/// - `flag` – include the field only if `true` (must be `bool`)
///
/// # Behavior
/// - Optional fields (`Option<T>`) are included only if `Some(value)`
/// - Arguments are formatted as `{prefix}{name}{delimiter}{value}`
/// - Field-level attributes override struct-level defaults
/// - Only one binary (struct-level or field-level) is allowed
///
/// # Example
///
/// ```rust,ignore
/// #[derive(ClapReverse)]
/// #[clap_reverse(display, binary = "echo")]
/// struct Echo {
///     #[clap_reverse(transparent)]
///     text: String,
///     #[clap_reverse(flag)]
///     loud: bool,
/// }
///
/// let echo = Echo { text: "Hello".into(), loud: true };
/// let cmd = echo.as_command();
/// println!("Command: `{echo}`"); // echo Hello --loud
/// ```
#[proc_macro_derive(ClapReverse, attributes(clap_reverse))]
pub fn derive_clap_reverse(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
    clap_reverse_impl::ClapReverseGenerator::parse(syn::parse_macro_input!(input as syn::DeriveInput))
        .and_then(|generator| generator.generate())
        .map(proc_macro::TokenStream::from)
        .unwrap_or_else(|e| e.into_compile_error().into())
}