From cbf6b8c3f661ab605f755896f4fb9852451f43aa Mon Sep 17 00:00:00 2001 From: "Hatter Jiang@Pixelbook" Date: Sat, 25 Jul 2020 21:53:30 +0800 Subject: [PATCH] feat: add information!() --- src/cmd_default.rs | 5 +++-- src/main.rs | 7 +++++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/cmd_default.rs b/src/cmd_default.rs index 6b23a32..c3b671d 100644 --- a/src/cmd_default.rs +++ b/src/cmd_default.rs @@ -1,5 +1,6 @@ use clap::{ App, Arg, ArgMatches, }; use crate::cmd::CommandError; +use crate::information; pub struct CommandDefault; @@ -10,8 +11,8 @@ impl CommandDefault { } pub fn run(_arg_matches: &ArgMatches) -> CommandError { - println!("Git status: {}", crate::git::check_git_status()); - println!("Git hash : {}", crate::git::get_git_hash().unwrap_or_else(|| "".to_owned())); + information!("Git status: {}", crate::git::check_git_status()); + information!("Git hash : {}", crate::git::get_git_hash().unwrap_or_else(|| "".to_owned())); error!("Default command is not implemented!"); Ok(()) } diff --git a/src/main.rs b/src/main.rs index a77c3f4..0591369 100644 --- a/src/main.rs +++ b/src/main.rs @@ -12,6 +12,9 @@ use cmd::{ Command, CommandError }; use cmd_default::CommandDefault; use cmd_new::CommandNew; +#[macro_export] macro_rules! information { + ($($arg:tt)+) => ( crate::print_in(&format!($($arg)+)); ) +} #[macro_export] macro_rules! success { ($($arg:tt)+) => ( crate::print_ok(&format!($($arg)+)); ) } @@ -19,6 +22,10 @@ use cmd_new::CommandNew; ($($arg:tt)+) => ( crate::print_wa(&format!($($arg)+)); ) } +#[inline] +fn print_in (msg: &str) { + println!("{b}[INFO]{e} {m}", b = "\x1B[1m", e = "\x1B[0m", m = msg); +} #[inline] fn print_ok (msg: &str) { println!("{g}{b}[ OK ]{e} {g}{m}{e}", g = "\x1B[92m", b = "\x1B[1m", e = "\x1B[0m", m = msg);