[cli] Use clap_app! macro and update version of clap.

Signed-off-by: Fletcher Nichol <fnichol@nichol.ca>
This commit is contained in:
Fletcher Nichol 2016-04-29 19:39:55 -06:00
parent 2a04c0a3f2
commit d9e89ad782
2 changed files with 23 additions and 22 deletions

View File

@ -12,6 +12,9 @@ A program to generate random names that look like 'used-jellyfish'.
[[bin]]
name = "names"
[dependencies]
clap = "~2.3"
names = { path = ".." }
[dependencies.clap]
version = "~2.3"
features = [ "suggestions", "color", "unstable" ]
[dependencies.names]
path = ".."

View File

@ -2,28 +2,26 @@
extern crate clap;
extern crate names;
use clap::{App, Arg};
use names::{Generator, Name};
fn main() {
let matches = App::new("names")
.version(&crate_version!()[..])
.author("\nAuthor: Fletcher Nichol <fnichol@nichol.ca>\n")
.about("A random name generator with results like `delirious-pail'.")
.arg(Arg::with_name("amount")
.help("Number of names to generate (default: 1)")
.index(1))
.arg(Arg::with_name("number")
.short("n")
.long("number")
.help("Adds a random number to the name(s)"))
.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()
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);