1pub struct Output {
7 quiet: bool,
8}
9
10impl Output {
11 pub fn new() -> Self {
13 Self { quiet: false }
14 }
15
16 pub fn with_quiet(quiet: bool) -> Self {
18 Self { quiet }
19 }
20
21 pub fn info(&self, msg: &str) {
23 if !self.quiet {
24 eprintln!("{}", msg);
25 }
26 }
27
28 pub fn success(&self, id: &str, msg: &str) {
30 if !self.quiet {
31 eprintln!(" ✓ {} {}", id, msg);
32 }
33 }
34
35 pub fn warn(&self, msg: &str) {
37 eprintln!(" ⚠ {}", msg);
38 }
39
40 pub fn error(&self, msg: &str) {
42 eprintln!(" ✗ {}", msg);
43 }
44}
45
46impl Default for Output {
47 fn default() -> Self {
48 Self::new()
49 }
50}
51
52#[cfg(test)]
53mod tests {
54 use super::*;
55
56 #[test]
57 fn output_new_is_not_quiet() {
58 let out = Output::new();
59 assert!(!out.quiet);
60 }
61
62 #[test]
63 fn output_default_is_not_quiet() {
64 let out = Output::default();
65 assert!(!out.quiet);
66 }
67
68 #[test]
69 fn output_with_quiet_true() {
70 let out = Output::with_quiet(true);
71 assert!(out.quiet);
72 }
73
74 #[test]
75 fn output_with_quiet_false() {
76 let out = Output::with_quiet(false);
77 assert!(!out.quiet);
78 }
79}