use cmder::{ParserMatches, Program}; fn main() { let mut program = Program::new(); program .author("vndaba") .description("A simple demo cli") .bin_name("demo") .version("0.1.0"); program .subcommand("greet") .argument("", "Pass the name to say hello to") .alias("g") .description("Simply greets the provided name") .option("-c --custom ", "Pass a custom greeting to use") .action(cmd::greet_cb); program.parse(); } mod cmd { use super::*; pub fn greet_cb(m: ParserMatches) { // we can safely unwrap the value since it it required and an error would have been thrown if no value was provided let name = m.get_arg("").unwrap(); let mut greeting = "Ahoy!".to_owned(); // Check if any args for exist if let Some(custom_grtng) = m.get_option_arg("") { greeting = custom_grtng; } println!("{greeting} {name}"); } }