glory_cli/config/
profile.rs

1use core::fmt;
2
3#[derive(Debug)]
4pub enum Profile {
5    Debug,
6    Release,
7    Named(String),
8}
9
10impl fmt::Display for Profile {
11    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
12        match self {
13            Self::Debug => write!(f, "debug"),
14            Self::Release => write!(f, "release"),
15            Self::Named(name) => write!(f, "{}", name),
16        }
17    }
18}
19
20impl Profile {
21    pub fn new(is_release: bool, release: &Option<String>, debug: &Option<String>) -> Self {
22        if is_release {
23            if let Some(release) = release {
24                Self::Named(release.clone())
25            } else {
26                Self::Release
27            }
28        } else if let Some(debug) = debug {
29            Self::Named(debug.clone())
30        } else {
31            Self::Debug
32        }
33    }
34
35    pub fn add_to_args(&self, args: &mut Vec<String>) {
36        match self {
37            Self::Debug => {}
38            Self::Release => {
39                args.push("--release".to_string());
40            }
41            Self::Named(name) => {
42                args.push(format!("--profile={}", name));
43            }
44        }
45    }
46}