1use std::env::Args;
4
5pub struct Config {
6 pub all_flag: bool,
7 pub show_detail_flag: bool,
8}
9
10impl Config {
11 pub fn new(mut args: Args) -> Result<Config, String> {
12 args.next();
13
14 let mut config = Config {
15 all_flag: false,
16 show_detail_flag: false,
17 };
18
19 for arg in args {
20 if arg.starts_with("-") {
21 for c in arg.chars().skip(1) {
22 match c {
23 'a' => config.all_flag = true,
24 'l' => config.show_detail_flag = true,
25 _ => return Err(format!("Invalid option: {}", c))
26 }
27 }
28 } else {
29 return Err(format!("Invalid argument: {}", arg))
30 }
31 }
32
33 Ok(config)
34 }
35}
36
37#[cfg(test)]
38mod tests {
39 #[test]
40 fn config_new() {
41 }
42}