codephrases 0.0.1

Generate human memorizable codephrases
Documentation
use clap::{App, Arg};
use codephrases::random_codephrase_from_rng;

fn main() {
    let matches = parser().get_matches();
    let num = matches
        .value_of("number")
        .unwrap()
        .parse::<usize>()
        .unwrap();
    let mut rng = rand::thread_rng();
    for _ in 0..num {
        println!("{}", random_codephrase_from_rng(&mut rng))
    }
}

fn pos_int(string: String) -> Result<(), String> {
    string
        .parse::<usize>()
        .map(|_| ())
        .map_err(|_| "Must be a positive integer.".into())
}

fn parser<'a, 'b>() -> App<'a, 'b> {
    App::new("codephrases")
        .version(env!("CARGO_PKG_VERSION"))
        .about("Generate random strings in the form \"AdjectiveNounVerbAdverb\"")
        .arg(
            Arg::with_name("number")
                .short("n")
                .long("number")
                .help("number of strings to generate")
                .default_value("1")
                .takes_value(true)
                .empty_values(false)
                .validator(pos_int),
        )
}