aboutsummaryrefslogtreecommitdiff
path: root/src/main.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs44
1 files changed, 19 insertions, 25 deletions
diff --git a/src/main.rs b/src/main.rs
index 6c8c723..397171c 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -15,15 +15,14 @@ extern crate quick_error;
use std::error::Error as StdError;
use std::fmt;
-use std::io::Write;
mod api;
mod bt;
mod cache;
+mod output;
mod render;
use clap::{App, Arg, ArgMatches};
-use termcolor::{Color, ColorChoice, ColorSpec, StandardStream, WriteColor};
use api::{Api, Profession, Skill};
use bt::{BuildTemplate, ExtraData, Legend, TraitChoice, Traitline};
@@ -273,6 +272,13 @@ fn run() -> MainResult<()> {
.conflicts_with_all(&["profession", "skill"]),
)
.arg(
+ Arg::with_name("quiet")
+ .help("Surpress console output except for the chat code.")
+ .short("q")
+ .long("quiet")
+ .takes_value(false),
+ )
+ .arg(
Arg::with_name("outfile")
.help("Specifies the output filename")
.short("o")
@@ -289,40 +295,28 @@ fn run() -> MainResult<()> {
run_searching(&mut api, &matches)?
};
- println!("Chat code: {}", build.chatlink());
+ if !matches.is_present("quiet") {
+ output::show_build_template(&build)?;
+ } else {
+ println!("{}", build.chatlink());
+ }
let mut renderer = render::Renderer::new(&mut api, Default::default());
let img = renderer.render_buildtemplate(&build).unwrap();
let filename = matches.value_of("outfile").unwrap();
img.save(filename)?;
+ if !matches.is_present("quiet") {
+ println!("Image saved in {}", filename);
+ }
+
Ok(())
}
fn main() {
let result = run();
if let Err(e) = result {
- 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).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 {
- 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();
- }
- }
+ output::show_error(e.as_ref()).expect("Error while displaying error");
+ std::process::exit(1);
}
}