diff --git a/src/config.rs b/src/config.rs new file mode 100644 index 0000000..c385d29 --- /dev/null +++ b/src/config.rs @@ -0,0 +1,26 @@ +use std::path::PathBuf; + +use colored::Colorize; +use directories::ProjectDirs; + +pub fn get_config_dir() -> Result { + // Construct the path to the config directory for this app + let project_dir = ProjectDirs::from("com", "va3zza", "tabset"); + + // Only pass back the directory if it exists + match project_dir { + Some(dir) => { + let config_dir = dir.config_dir(); + if config_dir.exists() { + Ok(config_dir.to_path_buf()) + } else { + eprintln!("{}\nPlease create: {}\nConfiguration info can be found at: ", + "tabset requires configuration files to be placed in its config directory.\nThis does not exist.".red(), + config_dir.display() + ); + Err(()) + } + } + None => Err(()), + } +}