BUGBUG: Fixed config not saving (i forgor)

This commit is contained in:
Gvidas Juknevičius 2024-04-15 17:53:14 +03:00
parent 3ba685448a
commit 057816bd65
Signed by: MCorange
GPG Key ID: 12B1346D720B7FBB
2 changed files with 22 additions and 0 deletions

13
config.json Normal file
View File

@ -0,0 +1,13 @@
{
"ytdlp": {
"path": "/usr/bin/yt-dlp",
"is_python": false
},
"spotdl": {
"path": "/home/mcorange/.local/bin/spotdl",
"is_python": false
},
"python": {
"path": ""
}
}

View File

@ -58,6 +58,7 @@ impl ConfigWrapper {
impl Config { impl Config {
pub async fn parse(cli: &CliArgs) -> Result<Self> { pub async fn parse(cli: &CliArgs) -> Result<Self> {
if !cli.config.exists() { if !cli.config.exists() {
log::info!("Config doesnt exist");
return Self::setup_config(&cli).await; return Self::setup_config(&cli).await;
} }
@ -127,6 +128,14 @@ impl Config {
} }
} }
s.save(cli.config.clone().into_std_path_buf())?;
Ok(s) Ok(s)
} }
fn save(&self, path: PathBuf) -> anyhow::Result<()> {
let data = serde_json::to_string_pretty(self)?;
std::fs::write(path, data)?;
Ok(())
}
} }