diff options
| author | lukeflo | 2024-11-08 13:36:09 +0100 |
|---|---|---|
| committer | lukeflo | 2024-11-08 13:36:09 +0100 |
| commit | 69653497b1e61f1b7c8ea19de30b4217eeebe71a (patch) | |
| tree | bf0f0d4db568e78be7f265e81d38ae5d70feea0a | |
| parent | dfd5f1847648c7692d24f91ab0cc5197bd2955c5 (diff) | |
| download | bibiman-69653497b1e61f1b7c8ea19de30b4217eeebe71a.tar.gz bibiman-69653497b1e61f1b7c8ea19de30b4217eeebe71a.zip | |
error handling if no file is passed as pos arg
| -rw-r--r-- | src/bibiman/bibisetup.rs | 33 |
1 files changed, 26 insertions, 7 deletions
diff --git a/src/bibiman/bibisetup.rs b/src/bibiman/bibisetup.rs index b5dae8e..e17997d 100644 --- a/src/bibiman/bibisetup.rs +++ b/src/bibiman/bibisetup.rs @@ -17,9 +17,12 @@ use biblatex::{self, Bibliography}; use biblatex::{ChunksExt, Type}; +use color_eyre::owo_colors::OwoColorize; use itertools::Itertools; use std::{fs, path::PathBuf}; +use crate::cliargs; + #[derive(Debug)] pub enum FileFormat { BibLatex, @@ -75,14 +78,30 @@ impl BibiSetup { // Check which file format the passed file has fn check_file_format(main_bibfile: &PathBuf) -> FileFormat { - let extension = main_bibfile.extension().unwrap().to_str(); + if main_bibfile.exists() { + let extension = main_bibfile.extension().unwrap().to_str(); - match extension { - Some("yml") => FileFormat::Hayagriva, - Some("yaml") => FileFormat::Hayagriva, - Some("bib") => FileFormat::BibLatex, - Some(_) => panic!("The extension {:?} is no valid bibfile", extension.unwrap()), - None => panic!("The given path {:?} holds no valid file", main_bibfile), + match extension { + // Some("yml") => FileFormat::Hayagriva, + // Some("yaml") => FileFormat::Hayagriva, + Some("bib") => FileFormat::BibLatex, + Some(_) => panic!( + "The extension \".{:?}\" is no valid bibfile", + extension.unwrap() + ), + None => panic!("The given path {:?} holds no valid file", main_bibfile), + } + } else { + println!( + "{}", + "No bibfile passed as argument. Please select a valid file." + .red() + .bold() + ); + println!(""); + println!("{}", cliargs::help_func()); + // panic!("No file passed as argument. Please choose a .bib file.") + std::process::exit(1) } } |
