summaryrefslogtreecommitdiff
path: root/rust/theBook/chapter-12-command-line-project/minigrep/src/main.rs
diff options
context:
space:
mode:
Diffstat (limited to 'rust/theBook/chapter-12-command-line-project/minigrep/src/main.rs')
-rw-r--r--rust/theBook/chapter-12-command-line-project/minigrep/src/main.rs19
1 files changed, 17 insertions, 2 deletions
diff --git a/rust/theBook/chapter-12-command-line-project/minigrep/src/main.rs b/rust/theBook/chapter-12-command-line-project/minigrep/src/main.rs
index ae7def5..a166fa2 100644
--- a/rust/theBook/chapter-12-command-line-project/minigrep/src/main.rs
+++ b/rust/theBook/chapter-12-command-line-project/minigrep/src/main.rs
@@ -1,6 +1,21 @@
-use std::env;
+use std::{env, process};
+
+use minigrep::Config;
fn main() {
+ // args() return iterator
+ // collect() extract iterator to collection we defined for args
let args: Vec<String> = env::args().collect();
- dbg!(args);
+
+ let config = Config::build(&args).unwrap_or_else(|err| {
+ eprintln!("Problem parsing arguments: {err}");
+ process::exit(1);
+ });
+
+ // we only care about error code since ok will return ()
+ // so `if let` is a ideal solution
+ if let Err(e) = minigrep::run(config) {
+ eprintln!("Application error: {e}");
+ process::exit(1);
+ }
}