From 1496c9f14fb8175194e5bb0599bb8ec34504c44d Mon Sep 17 00:00:00 2001 From: Sergio Gasquez Date: Tue, 15 Nov 2022 17:17:24 +0100 Subject: [PATCH] =?UTF-8?q?feat:=20=E2=9C=A8=20Add=20get=5Fconfig=5Fpath?= =?UTF-8?q?=20fn?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/config.rs | 13 +++++++++---- src/main.rs | 3 +-- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/config.rs b/src/config.rs index 08bb98e..1a1c955 100644 --- a/src/config.rs +++ b/src/config.rs @@ -30,10 +30,16 @@ pub struct Config { } impl Config { - /// Load the config from config file - pub fn load() -> Result { + /// Gets the path to the configuration file. + pub fn get_config_path() -> Result { let dirs = ProjectDirs::from("rs", "esp", "espup").unwrap(); let file = dirs.config_dir().join("espup.toml"); + Ok(file) + } + + /// Load the config from config file + pub fn load() -> Result { + let file = Self::get_config_path()?; let config = if let Ok(data) = read(&file) { toml::from_slice(&data) @@ -47,8 +53,7 @@ impl Config { /// Save the config to file pub fn save(&self) -> Result<(), Error> { - let dirs = ProjectDirs::from("rs", "esp", "espup").unwrap(); - let file = dirs.config_dir().join("espup.toml"); + let file = Self::get_config_path()?; let serialized = toml::to_string(&self.clone()) .into_diagnostic() diff --git a/src/main.rs b/src/main.rs index f467c7d..714912f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -294,8 +294,7 @@ fn uninstall(args: UninstallOpts) -> Result<(), Error> { remove_file(Path::new(&config.export_file))?; info!("{} Deleting config file", emoji::WRENCH); - let conf_dirs = ProjectDirs::from("rs", "esp", "espup").unwrap(); - let conf_file = conf_dirs.config_dir().join("espup.toml"); + let conf_file = Config::get_config_path()?; remove_file(conf_file)?; info!("{} Uninstallation successfully completed!", emoji::CHECK);