aboutsummaryrefslogtreecommitdiffhomepage
path: root/crates/mozart-core/src/advisory/auditor.rs
blob: 14c16938d7a5fb9f397baaf7dc3a65f3cfce32e9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
pub const FORMAT_TABLE: &str = "table";
pub const FORMAT_PLAIN: &str = "plain";
pub const FORMAT_JSON: &str = "json";
pub const FORMAT_SUMMARY: &str = "summary";
pub const FORMATS: [&str; 4] = [FORMAT_TABLE, FORMAT_PLAIN, FORMAT_JSON, FORMAT_SUMMARY];

pub const ABANDONED_IGNORE: &str = "ignore";
pub const ABANDONED_REPORT: &str = "report";
pub const ABANDONED_FAIL: &str = "fail";
pub const ABANDONEDS: [&str; 3] = [ABANDONED_IGNORE, ABANDONED_REPORT, ABANDONED_FAIL];

/// Mirrors `Auditor::FORMAT_*` constants.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
pub enum AuditFormat {
    #[default]
    Table,
    Plain,
    Json,
    Summary,
}

impl AuditFormat {
    pub fn as_str(self) -> &'static str {
        match self {
            Self::Table => FORMAT_TABLE,
            Self::Plain => FORMAT_PLAIN,
            Self::Json => FORMAT_JSON,
            Self::Summary => FORMAT_SUMMARY,
        }
    }
}

impl std::str::FromStr for AuditFormat {
    type Err = ();

    fn from_str(s: &str) -> Result<Self, Self::Err> {
        match s {
            FORMAT_TABLE => Ok(Self::Table),
            FORMAT_PLAIN => Ok(Self::Plain),
            FORMAT_JSON => Ok(Self::Json),
            FORMAT_SUMMARY => Ok(Self::Summary),
            _ => Err(()),
        }
    }
}

/// Mirrors `Auditor::ABANDONED_*` constants.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
pub enum AbandonedHandling {
    Ignore,
    Report,
    #[default]
    Fail,
}

impl AbandonedHandling {
    pub fn as_str(self) -> &'static str {
        match self {
            Self::Ignore => ABANDONED_IGNORE,
            Self::Report => ABANDONED_REPORT,
            Self::Fail => ABANDONED_FAIL,
        }
    }
}

impl std::str::FromStr for AbandonedHandling {
    type Err = ();

    fn from_str(s: &str) -> Result<Self, Self::Err> {
        match s {
            ABANDONED_IGNORE => Ok(Self::Ignore),
            ABANDONED_REPORT => Ok(Self::Report),
            ABANDONED_FAIL => Ok(Self::Fail),
            _ => Err(()),
        }
    }
}