mirror of
https://github.com/esp-rs/espup.git
synced 2025-10-02 07:10:36 +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 {
|
impl Config {
|
||||||
/// Load the config from config file
|
/// Gets the path to the configuration file.
|
||||||
pub fn load() -> Result<Self, Error> {
|
pub fn get_config_path() -> Result<PathBuf> {
|
||||||
let dirs = ProjectDirs::from("rs", "esp", "espup").unwrap();
|
let dirs = ProjectDirs::from("rs", "esp", "espup").unwrap();
|
||||||
let file = dirs.config_dir().join("espup.toml");
|
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) {
|
let config = if let Ok(data) = read(&file) {
|
||||||
toml::from_slice(&data)
|
toml::from_slice(&data)
|
||||||
@ -47,8 +53,7 @@ impl Config {
|
|||||||
|
|
||||||
/// Save the config to file
|
/// Save the config to file
|
||||||
pub fn save(&self) -> Result<(), Error> {
|
pub fn save(&self) -> Result<(), Error> {
|
||||||
let dirs = ProjectDirs::from("rs", "esp", "espup").unwrap();
|
let file = Self::get_config_path()?;
|
||||||
let file = dirs.config_dir().join("espup.toml");
|
|
||||||
|
|
||||||
let serialized = toml::to_string(&self.clone())
|
let serialized = toml::to_string(&self.clone())
|
||||||
.into_diagnostic()
|
.into_diagnostic()
|
||||||
|
@ -294,8 +294,7 @@ fn uninstall(args: UninstallOpts) -> Result<(), Error> {
|
|||||||
remove_file(Path::new(&config.export_file))?;
|
remove_file(Path::new(&config.export_file))?;
|
||||||
|
|
||||||
info!("{} Deleting config file", emoji::WRENCH);
|
info!("{} Deleting config file", emoji::WRENCH);
|
||||||
let conf_dirs = ProjectDirs::from("rs", "esp", "espup").unwrap();
|
let conf_file = Config::get_config_path()?;
|
||||||
let conf_file = conf_dirs.config_dir().join("espup.toml");
|
|
||||||
remove_file(conf_file)?;
|
remove_file(conf_file)?;
|
||||||
|
|
||||||
info!("{} Uninstallation successfully completed!", emoji::CHECK);
|
info!("{} Uninstallation successfully completed!", emoji::CHECK);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user