summaryrefslogtreecommitdiff
path: root/minigrep/src
diff options
context:
space:
mode:
Diffstat (limited to 'minigrep/src')
-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 })
}