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
use hersir::config::SessionMode;
use std::{convert::Infallible, fmt};

#[derive(Debug, PartialEq, Eq, Clone, Copy)]
pub enum Mode {
    Service,
    Interactive,
    Standard,
    Monitor,
}

pub fn parse_mode_from_str(mode: &str) -> Result<Mode, Infallible> {
    let mode_lowercase: &str = &mode.to_lowercase();
    let mode = match mode_lowercase {
        "service" => Mode::Service,
        "interactive" => Mode::Interactive,
        "monitor" => Mode::Monitor,
        _ => Mode::Standard,
    };

    Ok(mode)
}

impl fmt::Display for Mode {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        write!(f, "{:?}", self)
    }
}

#[allow(clippy::from_over_into)]
impl Into<SessionMode> for Mode {
    fn into(self) -> SessionMode {
        match self {
            Self::Monitor => SessionMode::Monitor,
            Self::Service => SessionMode::Monitor,
            Self::Interactive => SessionMode::Interactive,
            Self::Standard => SessionMode::Standard,
        }
    }
}