[cli] Use `clap_app!` macro and update version of clap.
Signed-off-by: Fletcher Nichol <fnichol@nichol.ca>
This commit is contained in:
parent
2a04c0a3f2
commit
d9e89ad782
|
@ -12,6 +12,9 @@ A program to generate random names that look like 'used-jellyfish'.
|
||||||
[[bin]]
|
[[bin]]
|
||||||
name = "names"
|
name = "names"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies.clap]
|
||||||
clap = "~2.3"
|
version = "~2.3"
|
||||||
names = { path = ".." }
|
features = [ "suggestions", "color", "unstable" ]
|
||||||
|
|
||||||
|
[dependencies.names]
|
||||||
|
path = ".."
|
||||||
|
|
|
@ -2,29 +2,27 @@
|
||||||
extern crate clap;
|
extern crate clap;
|
||||||
extern crate names;
|
extern crate names;
|
||||||
|
|
||||||
use clap::{App, Arg};
|
|
||||||
use names::{Generator, Name};
|
use names::{Generator, Name};
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let matches = App::new("names")
|
let (naming, amount) = {
|
||||||
.version(&crate_version!()[..])
|
let app = clap_app!(names =>
|
||||||
.author("\nAuthor: Fletcher Nichol <fnichol@nichol.ca>\n")
|
(version: &crate_version!()[..])
|
||||||
.about("A random name generator with results like `delirious-pail'.")
|
(author: "\nAuthor: Fletcher Nichol <fnichol@nichol.ca>\n")
|
||||||
.arg(Arg::with_name("amount")
|
(about: "A random name generator with results like `delirious-pail'.")
|
||||||
.help("Number of names to generate (default: 1)")
|
(@setting ColoredHelp)
|
||||||
.index(1))
|
(@arg amount: "Number of names to generate (default: 1)")
|
||||||
.arg(Arg::with_name("number")
|
(@arg number: -n --number "Adds a random number to the name(s)")
|
||||||
.short("n")
|
);
|
||||||
.long("number")
|
let matches = app.get_matches();
|
||||||
.help("Adds a random number to the name(s)"))
|
|
||||||
.get_matches();
|
|
||||||
|
|
||||||
let amount = value_t!(matches.value_of("amount"), usize).unwrap_or(1);
|
let amount = value_t!(matches.value_of("amount"), usize).unwrap_or(1);
|
||||||
let naming: Name = if matches.is_present("number") {
|
let naming: Name = if matches.is_present("number") {
|
||||||
Name::Numbered
|
Name::Numbered
|
||||||
} else {
|
} else {
|
||||||
Default::default()
|
Default::default()
|
||||||
};
|
};
|
||||||
|
(naming, amount)
|
||||||
|
};
|
||||||
|
|
||||||
let mut generator = Generator::with_naming(naming);
|
let mut generator = Generator::with_naming(naming);
|
||||||
for _ in 0..amount {
|
for _ in 0..amount {
|
||||||
|
|
Loading…
Reference in New Issue