From 6d94a5429f1db2a568aaf656746311a5bda17513 Mon Sep 17 00:00:00 2001 From: SinTan1729 Date: Tue, 28 Feb 2023 23:18:56 -0600 Subject: [PATCH] Exit gracefully if config file doesn't exist --- src/main.rs | 8 +++++++- src/structs.rs | 2 +- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/main.rs b/src/main.rs index 273ec2a..a4b1804 100644 --- a/src/main.rs +++ b/src/main.rs @@ -21,12 +21,18 @@ fn main() { config_file.push_str("/.config"); } config_file.push_str("/movie-rename/config"); + + if Path::new(config_file.as_str()).is_file() == false { + eprintln!("Error reading the config file. Pass --help to see help."); + exit(2); + } + let mut config = load_str!(config_file.as_str()).lines(); let api_key = config.next().unwrap_or(""); let pattern = config.next().unwrap_or("{title} ({year}) - {director}"); if api_key == "" { - eprintln!("Error reading the config file. Pass --help to see help."); + eprintln!("Could not read the API key. Pass --help to see help."); exit(2); } diff --git a/src/structs.rs b/src/structs.rs index 6707500..e93e46c 100644 --- a/src/structs.rs +++ b/src/structs.rs @@ -50,7 +50,7 @@ impl fmt::Display for MovieEntry { get_long_lang(self.language.as_str()) )); buffer.push_str(&format!("Directed by: {}, ", self.director)); - buffer.push_str(&format!("TMDb ID: {}", self.id)); + buffer.push_str(&format!("TMDB ID: {}", self.id)); // buffer.push_str(&format!("Synopsis: {}", self.overview)); write!(f, "{}", buffer) }