#[macro_use]
mod lib;

mod command;
mod constant;

use constant::*;
use std::env;

fn main() {
    if let Err(message) = validate_at_first() {
        return println!("{}", message);
    }

    let args = env::args()
        .skip(1)
        .collect::<Vec<String>>();

    command::execute(args);
}

fn validate_at_first() -> Result<(), String> {
    let current_dir = match env::current_dir() {
        Ok(dir)  => dir,
        Err(why) => return Err(format!("ERROR: {}", why)),
    };

    BANNED_DIRS
        .iter()
        .find(|d| current_dir.ends_with(d))
        .map_or(Ok(()), |dir| Err(format!(r#"ERROR: Cannot run in "{}"."#, dir)))
}

#[macro_use]
mod lib;

mod command;
mod constant;

use constant::*;
use std::env;

fn main() {
    if let Some(message) = validate_at_first() {
        return println!("{}", message);
    }

    let args = env::args()
        .skip(1)
        .collect::<Vec<String>>();

    command::execute(args);
}

fn validate_at_first() -> Option<String> {
    let current_dir = match env::current_dir() {
        Ok(dir)  => dir,
        Err(why) => return Some(format!("ERROR: {}", why)),
    };

    BANNED_DIRS
        .iter()
        .find(|d| current_dir.ends_with(d))
        .map(|d| format!(r#"ERROR: Cannot run in "{}"."#, d))
}

--- 
+++ 
@@ -8,7 +8,7 @@
 use std::env;
 
 fn main() {
-    if let Some(message) = validate_at_first() {
+    if let Err(message) = validate_at_first() {
         return println!("{}", message);
     }
 
@@ -19,14 +19,14 @@
     command::execute(args);
 }
 
-fn validate_at_first() -> Option<String> {
+fn validate_at_first() -> Result<(), String> {
     let current_dir = match env::current_dir() {
         Ok(dir)  => dir,
-        Err(why) => return Some(format!("ERROR: {}", why)),
+        Err(why) => return Err(format!("ERROR: {}", why)),
     };
 
     BANNED_DIRS
         .iter()
         .find(|d| current_dir.ends_with(d))
-        .map(|d| format!(r#"ERROR: Cannot run in "{}"."#, d))
+        .map_or(Ok(()), |dir| Err(format!(r#"ERROR: Cannot run in "{}"."#, dir)))
 }
Change type of validate_at_first()'s return value
