quickwit_common/
checklist.rs1use colored::{Color, Colorize};
21
22pub const BLUE_COLOR: Color = Color::TrueColor {
24 r: 22,
25 g: 74,
26 b: 209,
27};
28
29pub const GREEN_COLOR: Color = Color::TrueColor {
30 r: 22,
31 g: 209,
32 b: 142,
33};
34pub const WHITE_COLOR: Color = Color::TrueColor {
35 r: 255,
36 g: 255,
37 b: 255,
38};
39pub const RED_COLOR: Color = Color::TrueColor {
40 r: 230,
41 g: 0,
42 b: 34,
43};
44
45pub fn print_checklist(check_list_results: &[(&str, anyhow::Result<()>)]) {
46 eprintln!(
47 "\n{}\n{}",
48 "---------------------------------------------------".color(GREEN_COLOR),
49 " Connectivity checklist "
50 .color(WHITE_COLOR)
51 .on_color(GREEN_COLOR)
52 );
53 let mut errors = Vec::new();
54 for (check_item_name, check_item_result) in check_list_results {
55 let outcome_symbol = if check_item_result.is_ok() {
56 "✔".color(GREEN_COLOR) } else {
58 "✖".color(RED_COLOR) };
60 eprintln!(" {} {}", outcome_symbol, check_item_name);
61 if let Err(check_item_err) = check_item_result {
62 errors.push((check_item_name, check_item_err));
63 }
64 }
65 if errors.is_empty() {
66 println!();
67 return;
68 }
69 eprintln!(
70 "{}\n{}",
71 "---------------------------------------------------".color(RED_COLOR),
72 " Error Details ".color(WHITE_COLOR).on_color(RED_COLOR)
73 );
74 for (check_item_name, check_item_err) in errors {
75 eprintln!(
76 "\n{}\n{:?}",
77 format!(" ✖ {}", check_item_name).color(RED_COLOR),
78 check_item_err
79 );
80 }
81 eprintln!("\n\n");
82}
83
84pub fn run_checklist(checks: Vec<(&str, anyhow::Result<()>)>) {
88 print_checklist(&checks);
89 if !checks
90 .iter()
91 .all(|(_, check_items_res)| check_items_res.is_ok())
92 {
93 std::process::exit(1);
94 }
95}