Skip to content
Myr

exit_codes.rs

This file

Path

src/exit_codes.rs

74 lines · 1.8 KiB · Rust

Last changed by

Refactor: `merge_exit_codes` now takes an `impl IntoIterator<Item = ExitCode>`Niklas Mohrinbefore adoption45a8645

History of this file

Take it

The walk stopped after 200 commits: lines older than daf3046 point at it.

Add as-tree to the READMEJake Zimmermanbefore adoptiondaf3046

lines 1–3why, one step back
1#[derive(Debug, Clone, Copy, PartialEq)]
2pub enum ExitCode {3 Success,

Add -q/--quiet/--has-match flag (#813)Asha20before adoption334488c

line 4why, one step back
4 HasResults(bool),

Add as-tree to the READMEJake Zimmermanbefore adoptiondaf3046

lines 5–8why, one step back
5 GeneralError,
6 KilledBySigint,7}8

Fix clippy warningsDavid Peterbefore adoption2a2126c

lines 9–11why, one step back
9impl From<ExitCode> for i32 {
10 fn from(code: ExitCode) -> Self {11 match code {

Add as-tree to the READMEJake Zimmermanbefore adoptiondaf3046

line 12why, one step back
12 ExitCode::Success => 0,

Add -q/--quiet/--has-match flag (#813)Asha20before adoption334488c

line 13why, one step back
13 ExitCode::HasResults(has_results) => !has_results as i32,

Add as-tree to the READMEJake Zimmermanbefore adoptiondaf3046

lines 14–20why, one step back
14 ExitCode::GeneralError => 1,
15 ExitCode::KilledBySigint => 130,16 }17 }18}1920impl ExitCode {

Fix clippy warningsDavid Peterbefore adoption2a2126c

line 21why, one step back
21 fn is_error(self) -> bool {

Add -q/--quiet/--has-match flag (#813)Asha20before adoption334488c

line 22why, one step back
22 i32::from(self) != 0

Add as-tree to the READMEJake Zimmermanbefore adoptiondaf3046

lines 23–25why, one step back
23 }
24}25

Refactor: `merge_exit_codes` now takes an `impl IntoIterator<Item = ExitCode>`Niklas Mohrinbefore adoption45a8645

lines 26–27why, one step back
26pub fn merge_exitcodes(results: impl IntoIterator<Item = ExitCode>) -> ExitCode {
27 if results.into_iter().any(ExitCode::is_error) {

Add as-tree to the READMEJake Zimmermanbefore adoptiondaf3046

lines 28–38why, one step back
28 return ExitCode::GeneralError;
29 }30 ExitCode::Success31}3233#[cfg(test)]34mod tests {35 use super::*;3637 #[test]38 fn success_when_no_results() {

Refactor: `merge_exit_codes` now takes an `impl IntoIterator<Item = ExitCode>`Niklas Mohrinbefore adoption45a8645

line 39why, one step back
39 assert_eq!(merge_exitcodes([]), ExitCode::Success);

Add as-tree to the READMEJake Zimmermanbefore adoptiondaf3046

lines 40–44why, one step back
40 }
4142 #[test]43 fn general_error_if_at_least_one_error() {44 assert_eq!(

Refactor: `merge_exit_codes` now takes an `impl IntoIterator<Item = ExitCode>`Niklas Mohrinbefore adoption45a8645

line 45why, one step back
45 merge_exitcodes([ExitCode::GeneralError]),

Add as-tree to the READMEJake Zimmermanbefore adoptiondaf3046

lines 46–48why, one step back
46 ExitCode::GeneralError
47 );48 assert_eq!(

Refactor: `merge_exit_codes` now takes an `impl IntoIterator<Item = ExitCode>`Niklas Mohrinbefore adoption45a8645

line 49why, one step back
49 merge_exitcodes([ExitCode::KilledBySigint]),

Add as-tree to the READMEJake Zimmermanbefore adoptiondaf3046

lines 50–52why, one step back
50 ExitCode::GeneralError
51 );52 assert_eq!(

Refactor: `merge_exit_codes` now takes an `impl IntoIterator<Item = ExitCode>`Niklas Mohrinbefore adoption45a8645

line 53why, one step back
53 merge_exitcodes([ExitCode::KilledBySigint, ExitCode::Success]),

Add as-tree to the READMEJake Zimmermanbefore adoptiondaf3046

lines 54–56why, one step back
54 ExitCode::GeneralError
55 );56 assert_eq!(

Refactor: `merge_exit_codes` now takes an `impl IntoIterator<Item = ExitCode>`Niklas Mohrinbefore adoption45a8645

line 57why, one step back
57 merge_exitcodes([ExitCode::Success, ExitCode::GeneralError]),

Add as-tree to the READMEJake Zimmermanbefore adoptiondaf3046

lines 58–60why, one step back
58 ExitCode::GeneralError
59 );60 assert_eq!(

Refactor: `merge_exit_codes` now takes an `impl IntoIterator<Item = ExitCode>`Niklas Mohrinbefore adoption45a8645

line 61why, one step back
61 merge_exitcodes([ExitCode::GeneralError, ExitCode::KilledBySigint]),

Add as-tree to the READMEJake Zimmermanbefore adoptiondaf3046

lines 62–67why, one step back
62 ExitCode::GeneralError
63 );64 }6566 #[test]67 fn success_if_no_error() {

Refactor: `merge_exit_codes` now takes an `impl IntoIterator<Item = ExitCode>`Niklas Mohrinbefore adoption45a8645

line 68why, one step back
68 assert_eq!(merge_exitcodes([ExitCode::Success]), ExitCode::Success);

Add as-tree to the READMEJake Zimmermanbefore adoptiondaf3046

line 69why, one step back
69 assert_eq!(

Refactor: `merge_exit_codes` now takes an `impl IntoIterator<Item = ExitCode>`Niklas Mohrinbefore adoption45a8645

line 70why, one step back
70 merge_exitcodes([ExitCode::Success, ExitCode::Success]),

Add as-tree to the READMEJake Zimmermanbefore adoptiondaf3046

lines 71–74why, one step back
71 ExitCode::Success
72 );73 }74}