From 552513e3ce697bae320c349696f8f8c3d51b6a12 Mon Sep 17 00:00:00 2001 From: Evan Pratten Date: Sun, 23 Jan 2022 13:35:49 -0500 Subject: [PATCH] working on CLI interface --- src/config.rs | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 src/config.rs 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(()), + } +}