mirror of
https://github.com/esp-rs/espup.git
synced 2025-09-30 14:20:35 +00:00
feat: ✨ Add get_config_path fn
This commit is contained in:
parent
1b605ca442
commit
1496c9f14f
@ -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()
|
||||
|
@ -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);
|
||||
|
Loading…
x
Reference in New Issue
Block a user