feat: add information!()

This commit is contained in:
2020-07-25 21:53:30 +08:00
parent cea48c108a
commit cbf6b8c3f6
2 changed files with 10 additions and 2 deletions

View File

@@ -1,5 +1,6 @@
use clap::{ App, Arg, ArgMatches, }; use clap::{ App, Arg, ArgMatches, };
use crate::cmd::CommandError; use crate::cmd::CommandError;
use crate::information;
pub struct CommandDefault; pub struct CommandDefault;
@@ -10,8 +11,8 @@ impl CommandDefault {
} }
pub fn run(_arg_matches: &ArgMatches) -> CommandError { pub fn run(_arg_matches: &ArgMatches) -> CommandError {
println!("Git status: {}", crate::git::check_git_status()); information!("Git status: {}", crate::git::check_git_status());
println!("Git hash : {}", crate::git::get_git_hash().unwrap_or_else(|| "<none>".to_owned())); information!("Git hash : {}", crate::git::get_git_hash().unwrap_or_else(|| "<none>".to_owned()));
error!("Default command is not implemented!"); error!("Default command is not implemented!");
Ok(()) Ok(())
} }

View File

@@ -12,6 +12,9 @@ use cmd::{ Command, CommandError };
use cmd_default::CommandDefault; use cmd_default::CommandDefault;
use cmd_new::CommandNew; use cmd_new::CommandNew;
#[macro_export] macro_rules! information {
($($arg:tt)+) => ( crate::print_in(&format!($($arg)+)); )
}
#[macro_export] macro_rules! success { #[macro_export] macro_rules! success {
($($arg:tt)+) => ( crate::print_ok(&format!($($arg)+)); ) ($($arg:tt)+) => ( crate::print_ok(&format!($($arg)+)); )
} }
@@ -19,6 +22,10 @@ use cmd_new::CommandNew;
($($arg:tt)+) => ( crate::print_wa(&format!($($arg)+)); ) ($($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] #[inline]
fn print_ok (msg: &str) { fn print_ok (msg: &str) {
println!("{g}{b}[ OK ]{e} {g}{m}{e}", g = "\x1B[92m", b = "\x1B[1m", e = "\x1B[0m", m = msg); println!("{g}{b}[ OK ]{e} {g}{m}{e}", g = "\x1B[92m", b = "\x1B[1m", e = "\x1B[0m", m = msg);