|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+use std::env;
|
|
|
2
|
+use std::process;
|
|
|
3
|
+
|
|
|
4
|
+/// a struct to hold all of our configuration
|
|
|
5
|
+#[derive(Debug,PartialEq)]
|
|
|
6
|
+struct Config{
|
|
|
7
|
+ search: char,
|
|
|
8
|
+ line: String,
|
|
|
9
|
+}
|
|
|
10
|
+
|
|
|
11
|
+fn main() {
|
|
|
12
|
+ let args = env::args().collect();
|
|
|
13
|
+ print_arguments(&args);
|
|
|
14
|
+ //let conf = parse_arguments_simple(&args);
|
|
|
15
|
+ let res = parse_arguments(&args);
|
|
|
16
|
+ match res {
|
|
|
17
|
+ Ok(conf) => println!("{:?}", conf),
|
|
|
18
|
+ Err(_) => process::exit(1),
|
|
|
19
|
+ }
|
|
|
20
|
+
|
|
|
21
|
+}
|
|
|
22
|
+
|
|
|
23
|
+fn run() {
|
|
|
24
|
+
|
|
|
25
|
+}
|
|
|
26
|
+
|
|
|
27
|
+/// Parses relevant arguments, returning the filled Config in Result
|
|
|
28
|
+///
|
|
|
29
|
+///
|
|
|
30
|
+/// This function will parse the relevant arguments from the
|
|
|
31
|
+/// given <Strings>.
|
|
|
32
|
+/// Returns Config or Error Message in Result
|
|
|
33
|
+fn parse_arguments(args: &Vec<String>) -> Result<Config, String> {
|
|
|
34
|
+
|
|
|
35
|
+ if args.len() < 3 {
|
|
|
36
|
+ return Err("not ennugh parameters".to_string());
|
|
|
37
|
+ }
|
|
|
38
|
+
|
|
|
39
|
+ if args[1].chars().nth(0) == None {
|
|
|
40
|
+ return Err("char mismatch".to_string());
|
|
|
41
|
+ }
|
|
|
42
|
+
|
|
|
43
|
+ let config = Config{search: args[1].chars().nth(0).unwrap(), line: args[2].clone()};
|
|
|
44
|
+ Ok(config)
|
|
|
45
|
+}
|
|
|
46
|
+
|
|
|
47
|
+/// Parses relevant arguments, returning the filled Config
|
|
|
48
|
+///
|
|
|
49
|
+///
|
|
|
50
|
+/// This function will parse the relevant arguments from the
|
|
|
51
|
+/// given <Strings>.
|
|
|
52
|
+/// Returns Config
|
|
|
53
|
+#[allow(dead_code)]
|
|
|
54
|
+fn parse_arguments_simple(args: &Vec<String>) -> Config {
|
|
|
55
|
+ Config{search: args[1].chars().nth(0).unwrap(), line: args[2].clone()}
|
|
|
56
|
+}
|
|
|
57
|
+
|
|
|
58
|
+/// Prints elements of Vec
|
|
|
59
|
+///
|
|
|
60
|
+///
|
|
|
61
|
+/// This function will print all elements of Vec with "args found: <elem>" in
|
|
|
62
|
+/// each line
|
|
|
63
|
+///
|
|
|
64
|
+/// Returns nothing
|
|
|
65
|
+fn print_arguments(args: &Vec<String>) {
|
|
|
66
|
+ for s in args {
|
|
|
67
|
+ println!("args found: {}", s);
|
|
|
68
|
+ }
|
|
|
69
|
+}
|