use cliproc::{cli, proc, stage::Memory}; use cliproc::{Arg, Cli, Command, ExitCode, Help}; use std::env; // 1. Define the struct and the data required to perform its task struct Demo { name: String, count: Option, } // 2. Implement the `Command` trait to allow a struct to function as a command impl Command for Demo { // 2a. Map the command-line data to the struct's data fn interpret(cli: &mut Cli) -> cli::Result { cli.help(Help::with(HELP))?; Ok(Demo { name: cli.require(Arg::option("name").switch('n'))?, count: cli.get(Arg::option("count").switch('c'))?, }) } // 2b. Process the struct's data to perform its task fn execute(self) -> proc::Result { for _ in 0..self.count.unwrap_or(1) { println!("Hello {}!", self.name); } Ok(()) } } // 3. Build the command-line processor and run the command fn main() -> ExitCode { Cli::default().parse(env::args()).go::() } const HELP: &str = "\ A fast, low-level, and configurable command-line processor. Usage: demo [options] --name Options: --name, -n Name of the person to greet --count, -c Number of times to greet (default: 1) --help, -h Print this help information and exit ";