diff --git a/bin/src/context.rs b/bin/src/context.rs index 09dc422e..9a924f9b 100644 --- a/bin/src/context.rs +++ b/bin/src/context.rs @@ -78,6 +78,9 @@ impl Context { trace!("using temporary folder: {:?}", tmp.display()); let hemtt_folder = root.join(".hemtt"); trace!("using project folder: {:?}", root.display()); + if !hemtt_folder.exists() { + return Err(Error::ConfigNotFound); + } let out_folder = root.join(".hemttout"); trace!("using out folder: {:?}", out_folder.display()); create_dir_all(&out_folder)?; diff --git a/bin/src/lib.rs b/bin/src/lib.rs index c72714ac..10968b34 100644 --- a/bin/src/lib.rs +++ b/bin/src/lib.rs @@ -91,8 +91,11 @@ pub fn execute(cli: &Cli) -> Result<(), Error> { if !in_test && !matches!(cli.command, Some(Commands::Value(_))) { logging::init( cli.global.verbosity, - !matches!(cli.command, Some(Commands::Utils(_))), - ); + !matches!( + cli.command, + Some(Commands::Utils(_) | Commands::Wiki(_) | Commands::New(_) | Commands::Book(_)) + ), + )?; } #[cfg(debug_assertions)] diff --git a/bin/src/logging.rs b/bin/src/logging.rs index b11afc35..0fb45cc4 100644 --- a/bin/src/logging.rs +++ b/bin/src/logging.rs @@ -8,11 +8,16 @@ use tracing_subscriber::{ prelude::__tracing_subscriber_SubscriberExt, util::SubscriberInitExt, Layer, }; +use crate::Error; + /// Initialize the logger /// +/// # Errors +/// If `hemttout` is true, but no `.hemtt` folder is found +/// /// # Panics /// If the log file could not be created -pub fn init(verbosity: u8, hemttout: bool) { +pub fn init(verbosity: u8, hemttout: bool) -> Result<(), Error> { let format = tracing_subscriber::fmt::format() .without_time() .with_target(false) @@ -31,6 +36,12 @@ pub fn init(verbosity: u8, hemttout: bool) { }; if hemttout { + if !std::path::Path::new(".hemtt").exists() { + tracing_subscriber::registry() + .with(stdout.with_filter(filter)) + .init(); + return Err(Error::ConfigNotFound); + } create_dir_all(".hemttout").expect("Unable to create `.hemttout`"); let out_file = File::create(".hemttout/latest.log").expect("Unable to create `.hemttout/latest.log`"); @@ -48,4 +59,6 @@ pub fn init(verbosity: u8, hemttout: bool) { .with(stdout.with_filter(filter)) .init(); } + + Ok(()) }