Skip to main content

sl/
config.rs

1#[derive(Clone, Debug)]
2pub struct Config {
3    pub accident: bool, // -a
4    pub c51: bool,      // -c
5    pub logo: bool,     // -l
6    pub flying: bool,   // -F
7}
8
9impl Config {
10    pub fn from_args<I, T>(args: I) -> Self
11    where
12        I: IntoIterator<Item = T>,
13        T: AsRef<str>,
14    {
15        let mut config = Config {
16            accident: false,
17            c51: false,
18            logo: false,
19            flying: false,
20        };
21
22        for arg in args.into_iter() {
23            let arg_str = arg.as_ref();
24            if arg_str.starts_with('-') {
25                for ch in arg_str.chars().skip(1) {
26                    match ch {
27                        'a' => config.accident = true,
28                        'c' => config.c51 = true,
29                        'l' => config.logo = true,
30                        'F' => config.flying = true,
31                        _ => {}
32                    }
33                }
34            }
35        }
36
37        config
38    }
39}