Skip to content

Commit

Permalink
Merge c040935 into 03d7cbf
Browse files Browse the repository at this point in the history
  • Loading branch information
evuez committed Dec 18, 2017
2 parents 03d7cbf + c040935 commit ca5339a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 20 deletions.
2 changes: 2 additions & 0 deletions cli/Cargo.toml
Expand Up @@ -6,3 +6,5 @@ authors = ["Clement Delafargue <clement@delafargue.name>"]
[dependencies]
uuid_to_pokemon = { version = "^0.2", path = "../lib" }
uuid = { version = "0.5", features = ["v4"] }
structopt = "0.1.6"
structopt-derive = "0.1.6"
35 changes: 15 additions & 20 deletions 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<Uuid> = vec![];
let mut errors: Vec<String> = 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<Uuid>,
}

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));
}
}

0 comments on commit ca5339a

Please sign in to comment.