use cliproc::{cli, proc, stage::Memory};
use cliproc::{Arg, Cli, Command, ExitCode, Help};
use std::env;
struct Demo {
name: String,
count: Option<u8>,
}
impl Command for Demo {
fn interpret(cli: &mut Cli<Memory>) -> cli::Result<Self> {
cli.help(Help::with(HELP))?;
Ok(Demo {
name: cli.require(Arg::option("name").switch('n'))?,
count: cli.get(Arg::option("count").switch('c'))?,
})
}
fn execute(self) -> proc::Result {
for _ in 0..self.count.unwrap_or(1) {
println!("Hello {}!", self.name);
}
Ok(())
}
}
fn main() -> ExitCode {
Cli::default().parse(env::args()).go::<Demo>()
}
const HELP: &str = "\
A fast, low-level, and configurable command-line processor.
Usage:
demo [options] --name <name>
Options:
--name, -n <name> Name of the person to greet
--count, -c <count> Number of times to greet (default: 1)
--help, -h Print this help information and exit
";