feat: Add get_config_path fn

This commit is contained in:
Sergio Gasquez 2022-11-15 17:17:24 +01:00
parent 1b605ca442
commit 1496c9f14f
2 changed files with 10 additions and 6 deletions

View File

@ -30,10 +30,16 @@ pub struct Config {
}
impl Config {
/// Load the config from config file
pub fn load() -> Result<Self, Error> {
/// Gets the path to the configuration file.
pub fn get_config_path() -> Result<PathBuf> {
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<Self, Error> {
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()

View File

@ -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);