extern crate gumdrop;
#[macro_use] extern crate gumdrop_derive;
use std::env::args;
use gumdrop::Options;
#[derive(Debug, Default, Options)]
struct MyOptions {
#[options(free)]
free: Vec<String>,
#[options(help = "print help message")]
help: bool,
#[options(help = "give a string argument")]
string: Option<String>,
#[options(help = "give a number as an argument", meta = "N")]
number: Option<i32>,
#[options(help = "give a list of string items")]
item: Vec<String>,
#[options(count, help = "increase a counting value")]
count: u32,
#[options(no_short, help = "this option has no short form")]
long_option_only: bool,
}
fn main() {
let args: Vec<String> = args().collect();
let opts = match MyOptions::parse_args_default(&args[1..]) {
Ok(opts) => opts,
Err(e) => {
println!("{}: {}", args[0], e);
return;
}
};
if opts.help {
println!("Usage: {} [OPTIONS] [ARGUMENTS]", args[0]);
println!();
println!("{}", MyOptions::usage());
} else {
println!("{:#?}", opts);
}
}