diff options
author | fxqnlr <[email protected]> | 2023-04-23 21:47:37 +0200 |
---|---|---|
committer | fxqnlr <[email protected]> | 2023-04-23 21:47:37 +0200 |
commit | 3e65975227baa511f570e8223fccda5607cf905e (patch) | |
tree | f852fd5cc3b26a004cf7bfab054e86c0d74c4669 /src/config.rs | |
parent | 416f4dc383ff5a1194da3a5532a8e159a4a1dac0 (diff) | |
download | modlist-3e65975227baa511f570e8223fccda5607cf905e.tar modlist-3e65975227baa511f570e8223fccda5607cf905e.tar.gz modlist-3e65975227baa511f570e8223fccda5607cf905e.zip |
added config argument, remove devdir
Diffstat (limited to 'src/config.rs')
-rw-r--r-- | src/config.rs | 15 |
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 | ||
6 | use serde::{Deserialize, Serialize}; | 6 | use serde::{Deserialize, Serialize}; |
7 | 7 | ||
8 | use crate::{devdir, error::MLE}; | 8 | use crate::error::MLE; |
9 | 9 | ||
10 | #[derive(Debug, Clone, Serialize, Deserialize)] | 10 | #[derive(Debug, Clone, Serialize, Deserialize)] |
11 | pub struct Cfg { | 11 | pub struct Cfg { |
@@ -20,10 +20,13 @@ pub struct Apis { | |||
20 | } | 20 | } |
21 | 21 | ||
22 | impl Cfg { | 22 | impl 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 | } |