clap_reverse 0.1.1

Derive macro for building `std::process:Command` from a Rust struct
Documentation
//! Static binary at struct level
//! 
//! Shows using a fixed binary (`binary = "echo"`) instead of a field.
//! Transparent text argument is appended directly.
//! `Display` prints the equivalent command line.

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.
// `binary = "/my/binary/path"` at the struct level sets up a static path to the binary.
#[clap_reverse(display, binary = "echo")]
struct Echo {
    // Transparent fields are appended directly.
    #[clap_reverse(transparent)]
    text: String,
}

fn main() {
    let echo = Echo {
        text: "Hello, World!".to_string(),
    };

    println!("Echo structure: {echo:#?}");
    println!("Echo command: `{echo}`"); // 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");
    }
}