summaryrefslogtreecommitdiff
path: root/rust/theBook/chapter-12-command-line-project/minigrep/src/main.rs
diff options
context:
space:
mode:
authorgarhve <git@garhve.com>2023-01-11 11:13:11 +0800
committergarhve <git@garhve.com>2023-01-11 11:13:11 +0800
commitb01a4deacb27422c8a78791affc824d00c8841ab (patch)
treeea0b1a2ff1989795174d3229bf8d878d952f7535 /rust/theBook/chapter-12-command-line-project/minigrep/src/main.rs
parenta5ef3263fbf5b02c69ed9f26225f1d424e355c9f (diff)
finish chapter 12
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);
+ }
}