config/
weidu_log_options.rs

1use crate::log_options::LogOptions;
2
3pub struct WeiduLogOptions(Vec<LogOptions>);
4
5impl WeiduLogOptions {
6    pub fn new(options: Vec<LogOptions>) -> Self {
7        Self(options)
8    }
9    pub fn to_args(&self, path: &str) -> Vec<String> {
10        let mut out = vec![];
11        if self.0.contains(&LogOptions::LogAppend) {
12            out.push("--logapp".to_string());
13        }
14        for log in self.0.iter() {
15            match log {
16                LogOptions::LogAppend => {}
17                _ => out.extend(log.to_args(path)),
18            }
19        }
20        out
21    }
22}
23
24#[cfg(test)]
25mod tests {
26
27    use std::error::Error;
28
29    use super::*;
30    use pretty_assertions::assert_eq;
31    #[test]
32    fn test_split_log_mode() -> Result<(), Box<dyn Error>> {
33        let tests = vec![
34            (vec![LogOptions::Log("/".into())], vec!["--log", "/"]),
35            (
36                vec![LogOptions::Log("/".into()), LogOptions::LogAppend],
37                vec!["--logapp", "--log", "/"],
38            ),
39            (
40                vec![LogOptions::AutoLog, LogOptions::LogAppend],
41                vec!["--logapp", "--autolog"],
42            ),
43        ];
44        let empty_path = "".into();
45        for (test, expected) in tests {
46            assert_eq!(WeiduLogOptions::new(test).to_args(empty_path), expected)
47        }
48        Ok(())
49    }
50}