summaryrefslogtreecommitdiff
path: root/src/config.rs
diff options
context:
space:
mode:
authorfx <[email protected]>2023-04-23 21:57:09 +0200
committerfx <[email protected]>2023-04-23 21:57:09 +0200
commit99c84b5a81f395f4f094b157019e84bfc4459df6 (patch)
treef852fd5cc3b26a004cf7bfab054e86c0d74c4669 /src/config.rs
parent416f4dc383ff5a1194da3a5532a8e159a4a1dac0 (diff)
parent3e65975227baa511f570e8223fccda5607cf905e (diff)
downloadmodlist-99c84b5a81f395f4f094b157019e84bfc4459df6.tar
modlist-99c84b5a81f395f4f094b157019e84bfc4459df6.tar.gz
modlist-99c84b5a81f395f4f094b157019e84bfc4459df6.zip
Merge pull request 'added config argument, remove devdir' (#2) from dev into cache
Reviewed-on: http://raspberrypi.fritz.box:7920/fx/modlist/pulls/2
Diffstat (limited to 'src/config.rs')
-rw-r--r--src/config.rs15
1 files changed, 9 insertions, 6 deletions
diff --git a/src/config.rs b/src/config.rs
index a9a937e..23c7796 100644
--- a/src/config.rs
+++ b/src/config.rs
@@ -5,7 +5,7 @@ use std::{
5 5
6use serde::{Deserialize, Serialize}; 6use serde::{Deserialize, Serialize};
7 7
8use crate::{devdir, error::MLE}; 8use crate::error::MLE;
9 9
10#[derive(Debug, Clone, Serialize, Deserialize)] 10#[derive(Debug, Clone, Serialize, Deserialize)]
11pub struct Cfg { 11pub struct Cfg {
@@ -20,10 +20,13 @@ pub struct Apis {
20} 20}
21 21
22impl Cfg { 22impl Cfg {
23 pub fn init(filename: &str) -> MLE<Self> { 23 pub fn init(path: Option<String>) -> MLE<Self> {
24 let configfile = dirs::config_dir().unwrap().join(filename); 24 let configfile = match path {
25 Some(p) => String::from(p),
26 None => dirs::config_dir().unwrap().join("modlist.toml").to_string_lossy().into(),
27 };
25 28
26 let mut file = match File::open(devdir(configfile.to_str().unwrap())) { 29 let mut file = match File::open(&configfile) {
27 Ok(file) => file, 30 Ok(file) => file,
28 Err(err) => { 31 Err(err) => {
29 if err.kind() == std::io::ErrorKind::NotFound { 32 if err.kind() == std::io::ErrorKind::NotFound {
@@ -35,10 +38,10 @@ impl Cfg {
35 modrinth: String::from("https://api.modrinth.com/v2/"), 38 modrinth: String::from("https://api.modrinth.com/v2/"),
36 }, 39 },
37 }; 40 };
38 let mut file = File::create(devdir(configfile.to_str().unwrap()))?; 41 let mut file = File::create(&configfile)?;
39 println!("Created config file"); 42 println!("Created config file");
40 file.write_all(toml::to_string(&default_cfg)?.as_bytes())?; 43 file.write_all(toml::to_string(&default_cfg)?.as_bytes())?;
41 File::open(devdir(configfile.to_str().unwrap()))? 44 File::open(&configfile)?
42 } else { 45 } else {
43 return Err(err.into()); 46 return Err(err.into());
44 } 47 }