1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
#[macro_use] extern crate clap; use clap::{App, Arg}; pub fn run() { let matches = App::new("git-mander") .author(crate_authors!()) .version(crate_version!()) .about("TODO") .before_help("---BEFORE---") .after_help("---AFTER---") .arg( Arg::with_name("ARG1") .required(true) .help("This is our first argument"), ) .arg( Arg::with_name("ARG2") .required(false) .help("This is our second argument"), ) .arg( Arg::with_name("FLG1") .help("This is a flag") .short("f") .long("flag"), ) .arg( Arg::with_name("OPT1") .help("This is an option") .short("o") .long("option") .takes_value(true), ) .args(&[Arg::with_name("ARG3"), Arg::with_name("ARG4")]) .get_matches(); if let Some(arg1) = matches.value_of("ARG1") { println!("ARG1={}", arg1); } if matches.is_present("FLG1") { println!("Flag 1 was used"); } if let Some(opt1) = matches.value_of("OPT1") { println!("OPT1={}", opt1) } }