From e3dc106eb784f9e72ff328c70ff34b38a0bf1cec Mon Sep 17 00:00:00 2001 From: runebaas Date: Tue, 29 Oct 2019 00:19:27 +0100 Subject: [PATCH] Exit if specified fortunes file is not found --- src/main.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index 1f60fac..54ef5c6 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,4 +1,4 @@ -use std::{fs, thread, time}; +use std::{fs, thread, time, path, process}; use std::convert::TryFrom; use rand::prelude::*; use clap::{Arg, App}; @@ -92,6 +92,10 @@ fn parse_options(app: App) -> Options { } fn get_fortunes(filename: String) -> Vec { + if !path::Path::new(&filename).exists() { + println!("File '{}' does not found", filename); + process::exit(1); + } let fortune_file = fs::read_to_string(filename).expect("Cannot read fortune file"); let fortunes: Vec = fortune_file.split('%').map(ToOwned::to_owned).collect();