#[macro_use]
extern crate clap;
extern crate names;

use names::{Generator, Name};

fn main() {
    let (naming, amount) = {
        let app = clap_app!(names =>
                (version: &crate_version!()[..])
                (author: "\nAuthor: Fletcher Nichol <fnichol@nichol.ca>\n")
                (about: "A random name generator with results like `delirious-pail'.")
                (@setting ColoredHelp)
                (@arg amount: "Number of names to generate (default: 1)")
                (@arg number: -n --number "Adds a random number to the name(s)")
        );
        let matches = app.get_matches();
        let amount = value_t!(matches.value_of("amount"), usize).unwrap_or(1);
        let naming: Name = if matches.is_present("number") {
            Name::Numbered
        } else {
            Default::default()
        };
        (naming, amount)
    };

    let mut generator = Generator::with_naming(naming);
    for _ in 0..amount {
        println!("{}", generator.next().unwrap());
    }
}

#[macro_use]
extern crate clap;
extern crate names;

use clap::{AppSettings, Arg};

use names::{Generator, Name};

fn main() {
    let (naming, amount) = parse_cli_args();
    let mut generator = Generator::with_naming(naming);
    for _ in 0..amount {
        println!("{}", generator.next().unwrap());
    }
}

fn parse_cli_args() -> (Name, usize) {
    const FLAG_NUMBER: &str = "number";
    const ARG_AMOUNT: &str = "amount";

    let app = app_from_crate!()
        .name("names")
        .setting(AppSettings::ColoredHelp)
        .arg(
            Arg::with_name(FLAG_NUMBER)
                .short("n")
                .long(FLAG_NUMBER)
                .help("Adds a random number to the name(s)"),
        ).arg(
            Arg::with_name(ARG_AMOUNT)
                .help("Number of names to generate")
                .default_value("1"),
        );

    let matches = app.get_matches();
    let amount = value_t_or_exit!(matches.value_of(ARG_AMOUNT), usize);
    let naming: Name = if matches.is_present(FLAG_NUMBER) {
        Name::Numbered
    } else {
        Default::default()
    };

    (naming, amount)
}

Update clap code to use `app_from_crate!` macro.
[cli] Update clap code to use `app_from_crate!` macro.

Signed-off-by: Fletcher Nichol <77a0fd9e8048bbacd11af4e957bc6ff03b549f49@nichol.ca>
