From 60a72cf0576d44ed67c4530f2839c96b5fbaa96f Mon Sep 17 00:00:00 2001 From: Casey Rodarmor Date: Wed, 29 Apr 2020 22:56:34 -0700 Subject: [PATCH] Add color to `bin/gen` error messages type: development --- Cargo.lock | 1 + bin/gen/Cargo.toml | 3 ++- bin/gen/src/common.rs | 1 + bin/gen/src/main.rs | 4 +++- 4 files changed, 7 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 92e5251..d481ad6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -358,6 +358,7 @@ checksum = "2fad85553e09a6f881f739c29f0b00b0f01357c743266d478b68951ce23285f3" name = "gen" version = "0.0.0" dependencies = [ + "ansi_term 0.12.1", "askama", "cargo_toml", "chrono", diff --git a/bin/gen/Cargo.toml b/bin/gen/Cargo.toml index b4acaa2..3d88639 100644 --- a/bin/gen/Cargo.toml +++ b/bin/gen/Cargo.toml @@ -6,6 +6,7 @@ edition = "2018" publish = false [dependencies] +ansi_term = "0.12.1" askama = "0.9.0" cargo_toml = "0.8.0" chrono = "0.4.11" @@ -13,6 +14,7 @@ fehler = "1.0.0" git2 = "0.13.1" globset = "0.4.5" ignore = "0.4.14" +lexiclean = "0.0.1" libc = "0.2.69" log = "0.4.8" pretty_env_logger = "0.4.0" @@ -24,7 +26,6 @@ strum = "0.18.0" strum_macros = "0.18.0" tempfile = "3.1.0" walkdir = "2.3.1" -lexiclean = "0.0.1" [dependencies.serde] version = "1.0.106" diff --git a/bin/gen/src/common.rs b/bin/gen/src/common.rs index 1031cc5..bf2c56d 100644 --- a/bin/gen/src/common.rs +++ b/bin/gen/src/common.rs @@ -11,6 +11,7 @@ pub(crate) use std::{ str, }; +pub(crate) use ansi_term::Style; pub(crate) use askama::Template; pub(crate) use cargo_toml::Manifest; pub(crate) use chrono::{DateTime, NaiveDateTime, Utc}; diff --git a/bin/gen/src/main.rs b/bin/gen/src/main.rs index fc4eabd..75b972f 100644 --- a/bin/gen/src/main.rs +++ b/bin/gen/src/main.rs @@ -34,7 +34,9 @@ fn main() { pretty_env_logger::init(); if let Err(error) = Opt::from_args().run() { - eprintln!("{}", error); + let bold = Style::new().bold(); + let red = Style::new().fg(ansi_term::Color::Red).bold(); + eprintln!("{}: {}", red.paint("error"), bold.paint(error.to_string())); process::exit(EXIT_FAILURE); } }