]> git.lizzy.rs Git - rust.git/blob - src/summary.rs
Fix weird indentaion in chain
[rust.git] / src / summary.rs
1 #[must_use]
2 #[derive(Debug, Clone)]
3 pub struct Summary {
4     // Encountered e.g. an IO error.
5     has_operational_errors: bool,
6
7     // Failed to reformat code because of parsing errors.
8     has_parsing_errors: bool,
9
10     // Code is valid, but it is impossible to format it properly.
11     has_formatting_errors: bool,
12
13     // Formatted code differs from existing code (write-mode diff only).
14     pub has_diff: bool,
15 }
16
17 impl Summary {
18     pub fn new() -> Summary {
19         Summary {
20             has_operational_errors: false,
21             has_parsing_errors: false,
22             has_formatting_errors: false,
23             has_diff: false,
24         }
25     }
26
27     pub fn has_operational_errors(&self) -> bool {
28         self.has_operational_errors
29     }
30
31     pub fn has_parsing_errors(&self) -> bool {
32         self.has_parsing_errors
33     }
34
35     pub fn has_formatting_errors(&self) -> bool {
36         self.has_formatting_errors
37     }
38
39     pub fn add_operational_error(&mut self) {
40         self.has_operational_errors = true;
41     }
42
43     pub fn add_parsing_error(&mut self) {
44         self.has_parsing_errors = true;
45     }
46
47     pub fn add_formatting_error(&mut self) {
48         self.has_formatting_errors = true;
49     }
50
51     pub fn add_diff(&mut self) {
52         self.has_diff = true;
53     }
54
55     pub fn has_no_errors(&self) -> bool {
56         !(self.has_operational_errors || self.has_parsing_errors || self.has_formatting_errors ||
57           self.has_diff)
58     }
59
60     pub fn add(&mut self, other: Summary) {
61         self.has_operational_errors |= other.has_operational_errors;
62         self.has_formatting_errors |= other.has_formatting_errors;
63         self.has_parsing_errors |= other.has_parsing_errors;
64         self.has_diff |= other.has_diff;
65     }
66
67     pub fn print_exit_codes() {
68         let exit_codes = r#"Exit Codes:
69     0 = No errors
70     1 = Encountered operational errors e.g. an IO error
71     2 = Failed to reformat code because of parsing errors
72     3 = Code is valid, but it is impossible to format it properly
73     4 = Formatted code differs from existing code (write-mode diff only)"#;
74         println!("{}", exit_codes);
75     }
76 }