clap_reverse 0.1.1

Derive macro for building `std::process:Command` from a Rust struct
Documentation
//! Dynamic binary from a field
//! 
//! Shows using a binary path stored in a struct field (`#[clap_reverse(binary)]`).
//! Transparent text argument is appended directly.
//! `Display` prints the equivalent command line.

use std::path::PathBuf;
use clap_reverse::{AsCommand, ClapReverse};

// `#[derive(ClapReverse)]` generates `AsCommand` for the struct.
#[derive(Debug, ClapReverse)]
// `display` at the struct level implements `Display` to show the command line.
#[clap_reverse(display)]
struct Echo {
    // Field holding the dynamic binary path.
    #[clap_reverse(binary)]
    echo_binary: PathBuf,
    // Transparent fields are appended directly.
    #[clap_reverse(transparent)]
    text: String,
}

fn main() {
    let echo = Echo {
        echo_binary: PathBuf::from("/usr/bin/echo"),
        text: "Hello, World!".to_string(),
    };

    println!("Echo structure: {echo:#?}");
    println!("Echo command: `{echo}`"); // /usr/bin/echo Hello, World!
    println!("Echo execution result:"); // Hello, World!

    let exit_status = echo.as_command()
        .spawn()
        .expect("Failed to spawn `echo` command")
        .wait()
        .expect("Failed to wait on `echo` command");

    if !exit_status.success() {
        eprintln!("Something went wrong executing `echo` command");
    }
}