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
use std::str::FromStr;

#[derive(Clone, Debug, serde::Deserialize, serde::Serialize)]
#[cfg_attr(structopt, derive(structopt::StructOpt))]
pub enum Mode {
    /// Checks all tracked issues. More efficient than running the track macros during build time,
    /// as it can asynchronously obtain all information.
    Pipe,
    /// Runs checks during build time. `Level::Warn` corresponds to build warnings, `Level::Error`
    /// to build errors.
    Emit(Level),
    /// Performs no actions after parsing the attribute.
    Noop,
}

impl FromStr for Mode {
    type Err = &'static str;

    fn from_str(s: &str) -> Result<Self, Self::Err> {
        match s {
            "Pipe" => Ok(Mode::Pipe),
            "Emit(Warn)" => Ok(Mode::Emit(Level::Warn)),
            "Emit(Error)" => Ok(Mode::Emit(Level::Error)),
            _ => Err("unrecognized Mode"),
        }
    }
}

impl Default for Mode {
    fn default() -> Self {
        Mode::Emit(Level::Warn)
    }
}

#[derive(Clone, Debug, serde::Deserialize, serde::Serialize)]
pub enum Level {
    Warn,
    Error,
}