MVP.
This commit is contained in:
parent
f852f53302
commit
b7557465ef
20
Cargo.lock
generated
20
Cargo.lock
generated
@ -2,6 +2,7 @@
|
|||||||
name = "names"
|
name = "names"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
|
"clap 1.4.0 (git+https://github.com/kbknapp/clap-rs?rev=40104af)",
|
||||||
"rand 0.3.11 (registry+https://github.com/rust-lang/crates.io-index)",
|
"rand 0.3.11 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
]
|
]
|
||||||
|
|
||||||
@ -14,6 +15,20 @@ dependencies = [
|
|||||||
"winapi-build 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
"winapi-build 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "ansi_term"
|
||||||
|
version = "0.6.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "clap"
|
||||||
|
version = "1.4.0"
|
||||||
|
source = "git+https://github.com/kbknapp/clap-rs?rev=40104af#40104afe9d124b658569656ca643dc0a9d813216"
|
||||||
|
dependencies = [
|
||||||
|
"ansi_term 0.6.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
"strsim 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "libc"
|
name = "libc"
|
||||||
version = "0.1.10"
|
version = "0.1.10"
|
||||||
@ -29,6 +44,11 @@ dependencies = [
|
|||||||
"winapi 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)",
|
"winapi 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "strsim"
|
||||||
|
version = "0.4.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "winapi"
|
name = "winapi"
|
||||||
version = "0.2.4"
|
version = "0.2.4"
|
||||||
|
@ -4,4 +4,6 @@ version = "0.1.0"
|
|||||||
authors = ["Fletcher Nichol <fnichol@nichol.ca>"]
|
authors = ["Fletcher Nichol <fnichol@nichol.ca>"]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
# pending a release which includes https://github.com/kbknapp/clap-rs/pull/257
|
||||||
|
clap = { git = "https://github.com/kbknapp/clap-rs", rev = "40104af" }
|
||||||
rand = "0.3.0"
|
rand = "0.3.0"
|
||||||
|
28
src/main.rs
28
src/main.rs
@ -2,12 +2,40 @@ extern crate rand;
|
|||||||
|
|
||||||
use rand::Rng;
|
use rand::Rng;
|
||||||
|
|
||||||
|
#[macro_use]
|
||||||
|
extern crate clap;
|
||||||
|
|
||||||
|
use clap::{App, Arg};
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
|
let matches = App::new("names")
|
||||||
|
.version(&crate_version!()[..])
|
||||||
|
.author("Fletcher Nichol <fnichol@nichol.ca>")
|
||||||
|
.about("Random name generator")
|
||||||
|
.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"), u32).unwrap_or(1);
|
||||||
let adjectives = Dict::new(ADJECTIVE_WORDS);
|
let adjectives = Dict::new(ADJECTIVE_WORDS);
|
||||||
let nouns = Dict::new(NOUN_WORDS);
|
let nouns = Dict::new(NOUN_WORDS);
|
||||||
|
|
||||||
|
for _ in 0..amount {
|
||||||
|
if matches.is_present("number") {
|
||||||
|
let number = rand::thread_rng().gen_range(1, 10000);
|
||||||
|
println!("{}-{}-{:04}", adjectives.random(), nouns.random(), number);
|
||||||
|
} else {
|
||||||
println!("{}-{}", adjectives.random(), nouns.random());
|
println!("{}-{}", adjectives.random(), nouns.random());
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
struct Dict<'a> {
|
struct Dict<'a> {
|
||||||
words: &'a [&'a str],
|
words: &'a [&'a str],
|
||||||
|
Loading…
Reference in New Issue
Block a user