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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
use std::collections::HashMap;
use colored::*;
pub fn parse<'a>(conditionals:Vec::<&str>,unconditionals:Vec::<&str>) -> Result<(HashMap<String,String>,HashMap<String,String>),String>{
use std::env;
let mut conditionals_map: HashMap<String,String> = HashMap::with_capacity(conditionals.len());
let mut unconditionals_map: HashMap<String,String> = HashMap::with_capacity(unconditionals.len());
for i in conditionals {
conditionals_map.insert(i.to_string(),"".to_string());
}
for i in &unconditionals {
unconditionals_map.insert(i.to_string(),"".to_string());
}
let args = env::args().collect::<Vec<String>>();
for (n,i) in args.iter().enumerate() {
if conditionals_map.contains_key(i) {
if args.len() < n + 1 {
println!("args not properly formated");
return Err(String::from("Results not properly formatted"));
}
conditionals_map.insert(i.to_string(),args[n+1].clone());
}
}
for (n,i) in args.iter().enumerate() {
if unconditionals_map.contains_key(i) {
if args.len() < n + 1 {
println!("args not properly formated");
return Err(String::from("Results not properly formatted"));
}
unconditionals_map.insert(i.to_string(),args[n+1].clone());
}
}
for i in &unconditionals {
if unconditionals_map.get_key_value(*i).unwrap().1 == ""{
let error = format!("Mandatory flag {} not included",i.blue());
print!("\n \n");
print!("{}","mandatory flags ".red());
for i in unconditionals {
print!("{} ",i.green());
}
print!("{}"," were not included \n \n".red());
return Err(error);
}
}
let to_return = Ok((conditionals_map,unconditionals_map));
return to_return;
}