Skip to main content

j_cli/util/
log.rs

1/// 打印普通信息
2#[macro_export]
3macro_rules! info {
4    ($($arg:tt)*) => {{
5        println!($($arg)*)
6    }};
7}
8
9/// 打印错误信息
10#[macro_export]
11macro_rules! error {
12    ($($arg:tt)*) => {{
13        use colored::Colorize;
14        eprint!("{}", "[ERROR] ".red());
15        eprintln!($($arg)*)
16    }};
17}
18
19/// 打印 usage 提示
20#[macro_export]
21macro_rules! usage {
22    ($($arg:tt)*) => {{
23        use colored::Colorize;
24        print!("{}", "💡 Usage: ".green());
25        println!($($arg)*)
26    }};
27}
28
29/// 打印 debug 日志(仅 verbose 模式下输出)
30#[macro_export]
31macro_rules! debug_log {
32    ($config:expr, $($arg:tt)*) => {{
33        if $config.is_verbose() {
34            println!($($arg)*)
35        }
36    }};
37}
38
39/// 打印分隔线
40#[allow(dead_code)]
41pub fn print_line() {
42    println!("- - - - - - - - - - - - - - - - - - - - - - -");
43}
44
45/// 首字母大写
46pub fn capitalize_first_letter(s: &str) -> String {
47    let mut chars = s.chars();
48    match chars.next() {
49        None => String::new(),
50        Some(c) => c.to_uppercase().collect::<String>() + chars.as_str(),
51    }
52}