From b01a4deacb27422c8a78791affc824d00c8841ab Mon Sep 17 00:00:00 2001 From: garhve Date: Wed, 11 Jan 2023 11:13:11 +0800 Subject: finish chapter 12 --- .../minigrep/src/main.rs | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) (limited to 'rust/theBook/chapter-12-command-line-project/minigrep/src/main.rs') 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 = 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); + } } -- cgit v1.2.3-70-g09d2