diff --git a/cli/Cargo.toml b/cli/Cargo.toml index 8cc1c79..e3aad40 100644 --- a/cli/Cargo.toml +++ b/cli/Cargo.toml @@ -6,3 +6,5 @@ authors = ["Clement Delafargue "] [dependencies] uuid_to_pokemon = { version = "^0.2", path = "../lib" } uuid = { version = "0.5", features = ["v4"] } +structopt = "0.1.6" +structopt-derive = "0.1.6" diff --git a/cli/src/bin/uuid-to-pokemon.rs b/cli/src/bin/uuid-to-pokemon.rs index 9adbb5b..60c4d7a 100644 --- a/cli/src/bin/uuid-to-pokemon.rs +++ b/cli/src/bin/uuid-to-pokemon.rs @@ -1,33 +1,28 @@ extern crate uuid; extern crate uuid_to_pokemon; +extern crate structopt; +#[macro_use] +extern crate structopt_derive; -use std::{env, process}; use uuid::Uuid; use uuid_to_pokemon::uuid_to_pokemon; +use structopt::StructOpt; -fn main() { - let mut uuids: Vec = vec![]; - let mut errors: Vec = vec![]; - - for arg in env::args().skip(1) { - match Uuid::parse_str(&arg) { - Ok(u) => uuids.push(u), - Err(_) => errors.push(arg), - } - } +#[derive(StructOpt)] +#[structopt(name = "UUID to POKEMON")] +struct Opt { + #[structopt(help = "List of UUIDs")] + uuids: Vec, +} - if uuids.len() == 0 && errors.len() == 0 { - uuids.push(Uuid::new_v4()); - } +fn main() { + let mut opt = Opt::from_args(); - if errors.len() > 0 { - for e in errors { - eprintln!("{} is not a valid UUID", e); - } - process::exit(1); + if opt.uuids.len() == 0 { + opt.uuids.push(Uuid::new_v4()); } - for u in uuids { + for u in opt.uuids { println!("{}\t{}", u, uuid_to_pokemon(u)); } }