diff options
author | Daniel Schadt <kingdread@gmx.de> | 2019-12-07 17:14:32 +0100 |
---|---|---|
committer | Daniel Schadt <kingdread@gmx.de> | 2019-12-07 17:14:32 +0100 |
commit | 17f3c1a5023ff0457299b272a608ba45875841c7 (patch) | |
tree | e026f06d3568fcbf99cbe35cb3f424e01b81adf1 /src/main.rs | |
parent | daacf2ee3d5da8f672d1403657997c7f20a2893a (diff) | |
download | kondou-17f3c1a5023ff0457299b272a608ba45875841c7.tar.gz kondou-17f3c1a5023ff0457299b272a608ba45875841c7.tar.bz2 kondou-17f3c1a5023ff0457299b272a608ba45875841c7.zip |
implement chatlink parsing
Diffstat (limited to 'src/main.rs')
-rw-r--r-- | src/main.rs | 30 |
1 files changed, 23 insertions, 7 deletions
diff --git a/src/main.rs b/src/main.rs index e0d0e89..b241eb5 100644 --- a/src/main.rs +++ b/src/main.rs @@ -4,6 +4,7 @@ extern crate image; extern crate imageproc; extern crate itertools; extern crate md5; +extern crate num_enum; extern crate reqwest; extern crate rusttype; extern crate termcolor; @@ -21,7 +22,7 @@ mod cache; mod render; use clap::{App, Arg, ArgMatches}; -use termcolor::{StandardStream, WriteColor, ColorSpec, Color, ColorChoice}; +use termcolor::{Color, ColorChoice, ColorSpec, StandardStream, WriteColor}; use api::{Api, Profession, Skill}; use bt::{BuildTemplate, ExtraData, Legend, TraitChoice, Traitline}; @@ -189,6 +190,11 @@ fn run_searching(api: &mut Api, matches: &ArgMatches) -> MainResult<BuildTemplat Ok(build) } +fn run_chatlink(api: &mut Api, matches: &ArgMatches) -> MainResult<BuildTemplate> { + let link = matches.value_of("chatlink").unwrap(); + Ok(BuildTemplate::from_chatlink(api, link)?) +} + fn validate_traitline_format(input: String) -> Result<(), String> { let parts = input.split(':').collect::<Vec<_>>(); if parts.len() != 4 { @@ -278,7 +284,7 @@ fn run() -> MainResult<()> { let mut api = Api::new(cache::FileCache::new()); let build = match matches.is_present("chatlink") { false => run_searching(&mut api, &matches)?, - true => unimplemented!(), + true => run_chatlink(&mut api, &matches)?, }; println!("Chat code: {}", build.chatlink()); @@ -297,14 +303,24 @@ fn main() { let mut error_color = ColorSpec::new(); error_color.set_fg(Some(Color::Red)); let mut stderr = StandardStream::stderr(ColorChoice::Auto); - stderr.set_color(&error_color); - write!(stderr, "[Error]"); - stderr.reset(); - writeln!(stderr, " {}", e); + stderr.set_color(&error_color).unwrap(); + write!(stderr, "[Error]").unwrap(); + stderr.reset().unwrap(); + writeln!(stderr, " {}", e).unwrap(); + let mut source = e.source(); + if source.is_none() { + source = e.cause(); + } while let Some(s) = source { - eprintln!(" caused by {}", s); + stderr.set_color(&error_color).unwrap(); + write!(stderr, " [caused by]").unwrap(); + stderr.reset().unwrap(); + writeln!(stderr, " {}", s).unwrap(); source = s.source(); + if source.is_none() { + source = s.cause(); + } } } } |