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
use core::fmt;

#[derive(Debug)]
pub enum Profile {
    Debug,
    Release,
    Named(String),
}

impl fmt::Display for Profile {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        match self {
            Self::Debug => write!(f, "debug"),
            Self::Release => write!(f, "release"),
            Self::Named(name) => write!(f, "{}", name),
        }
    }
}

impl Profile {
    pub fn new(is_release: bool, release: &Option<String>, debug: &Option<String>) -> Self {
        if is_release {
            if let Some(release) = release {
                Self::Named(release.clone())
            } else {
                Self::Release
            }
        } else if let Some(debug) = debug {
            Self::Named(debug.clone())
        } else {
            Self::Debug
        }
    }

    pub fn add_to_args(&self, args: &mut Vec<String>) {
        match self {
            Self::Debug => {}
            Self::Release => {
                args.push("--release".to_string());
            }
            Self::Named(name) => {
                args.push(format!("--profile={}", name));
            }
        }
    }
}