wasmer_cli/commands/package/common/
macros.rs

1macro_rules! make_spinner {
2    ($quiet:expr, $msg:expr) => {{
3        let pb = indicatif::ProgressBar::new_spinner();
4        if $quiet {
5            pb.set_draw_target(indicatif::ProgressDrawTarget::hidden());
6        }
7
8        pb.enable_steady_tick(std::time::Duration::from_millis(500));
9        pb.set_style(
10            indicatif::ProgressStyle::with_template("{spinner:.magenta} {msg}")
11                .unwrap()
12                .tick_strings(&["✶", "✸", "✹", "✺", "✹", "✷", "✶"]),
13        );
14
15        pb.set_message($msg);
16        pb
17    }};
18
19    ($quiet:expr, $msg:expr, $($spinner:expr),+) => {{
20        let pb = indicatif::ProgressBar::new_spinner();
21        if $quiet {
22            pb.set_draw_target(indicatif::ProgressDrawTarget::hidden());
23        }
24
25        pb.enable_steady_tick(std::time::Duration::from_millis(500));
26        pb.set_style(
27            indicatif::ProgressStyle::with_template("{spinner:.magenta} {msg}")
28                .unwrap()
29                .tick_strings(&[$($spinner),+]),
30        );
31
32        pb.set_message($msg);
33        pb
34    }};
35}
36
37macro_rules! spinner_ok {
38    ($pb:expr, $msg: expr) => {
39        $pb.set_style(
40            indicatif::ProgressStyle::with_template(&format!("{} {{msg}}", "✔".green().bold()))
41                .unwrap(),
42        );
43        $pb.finish_with_message(format!("{}", $msg.bold()));
44    };
45}
46
47macro_rules! spinner_err {
48    ($pb:expr, $msg: expr) => {
49        $pb.set_style(
50            indicatif::ProgressStyle::with_template(&format!("{} {{msg}}", "✘".red().bold()))
51                .unwrap(),
52        );
53        $pb.finish_with_message(format!("{}", $msg.bold()));
54    };
55}
56
57macro_rules! bin_name {
58    () => {
59        match std::env::args().nth(0) {
60            Some(n) => n,
61            None => String::from("wasmer"),
62        }
63    };
64}
65
66pub(crate) use bin_name;
67pub(crate) use make_spinner;
68pub(crate) use spinner_err;
69pub(crate) use spinner_ok;