aboutsummaryrefslogtreecommitdiff
path: root/src/main.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs30
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();
+ }
}
}
}