diff --git a/src/error.rs b/src/error.rs index 9b75c87..3d4bf92 100644 --- a/src/error.rs +++ b/src/error.rs @@ -84,4 +84,10 @@ pub enum Error { emoji::ERROR )] FailedToRemoveFile(String), + #[diagnostic(code(espup::wrong_export_file))] + #[error( + "{} Wrong export file destination: '{0}'. Please, use an absolte or releative path (including the file and its extension).", + emoji::ERROR + )] + WrongExportFile(String), } diff --git a/src/main.rs b/src/main.rs index 099733d..a3efe71 100644 --- a/src/main.rs +++ b/src/main.rs @@ -20,7 +20,7 @@ use log::{debug, info, warn}; use miette::Result; use std::{ collections::HashSet, - fs::{remove_dir_all, remove_file, File}, + fs::{metadata, remove_dir_all, remove_file, File}, io::Write, path::PathBuf, }; @@ -428,6 +428,10 @@ fn clear_dist_folder() -> Result<(), Error> { /// Returns the absolute path to the export file, uses the DEFAULT_EXPORT_FILE if no arg is provided. fn get_export_file(export_file: Option) -> Result { if let Some(export_file) = export_file { + let metadata = export_file.metadata()?; + if !metadata.is_file() { + return Err(Error::WrongExportFile(export_file.display().to_string())); + } if export_file.is_absolute() { Ok(export_file) } else {