summaryrefslogtreecommitdiff
path: root/minigrep
diff options
context:
space:
mode:
authorAdam Carpenter <53hornet@gmail.com>2019-02-28 09:12:04 -0500
committerAdam Carpenter <53hornet@gmail.com>2019-02-28 09:12:04 -0500
commit131a4e22e2fb3afa8ec0a8a35945d9511e41a4f9 (patch)
tree8b220451980fb54beca02f8279f5ed52b31c9eaa /minigrep
parentb43fca42427dbd276ca2dd1d712611b6dea4338c (diff)
downloadlearning-rust-131a4e22e2fb3afa8ec0a8a35945d9511e41a4f9.tar.xz
learning-rust-131a4e22e2fb3afa8ec0a8a35945d9511e41a4f9.zip
Removed build files from repo.
Diffstat (limited to 'minigrep')
-rw-r--r--minigrep/src/lib.rs14
1 files changed, 9 insertions, 5 deletions
diff --git a/minigrep/src/lib.rs b/minigrep/src/lib.rs
index 9f0adbd..bf7118f 100644
--- a/minigrep/src/lib.rs
+++ b/minigrep/src/lib.rs
@@ -20,13 +20,17 @@ impl Config {
let filename = args[2].clone();
let mut case_sensitive = env::var("CASE_INSENSITIVE").is_err();
- if args.nth(3) == "-i" {
- case_sensitive = false;
- }
- else if args[3] == "-s" {
- case_sensitive = true;
+ // override environment variable if cli arg is present
+ if args.len() > 3 {
+ if args[3] == "-s" {
+ case_sensitive = true;
+ }
+ else if args[3] == "-i" {
+ case_sensitive = false;
+ }
}
+
Ok(Config { query, filename, case_sensitive })
}