diff options
Diffstat (limited to 'src/config.rs')
-rw-r--r-- | src/config.rs | 18 |
1 files changed, 13 insertions, 5 deletions
diff --git a/src/config.rs b/src/config.rs index ded0062..1b54d5f 100644 --- a/src/config.rs +++ b/src/config.rs | |||
@@ -1,8 +1,11 @@ | |||
1 | use std::{fs::File, io::{Read, Write}}; | 1 | use std::{ |
2 | fs::File, | ||
3 | io::{Read, Write}, | ||
4 | }; | ||
2 | 5 | ||
3 | use serde::{Serialize, Deserialize}; | 6 | use serde::{Deserialize, Serialize}; |
4 | 7 | ||
5 | use crate::{error::MLE, devdir}; | 8 | use crate::{devdir, error::MLE}; |
6 | 9 | ||
7 | #[derive(Debug, Clone, Serialize, Deserialize)] | 10 | #[derive(Debug, Clone, Serialize, Deserialize)] |
8 | pub struct Cfg { | 11 | pub struct Cfg { |
@@ -24,10 +27,15 @@ impl Cfg { | |||
24 | Err(err) => { | 27 | Err(err) => { |
25 | if err.kind() == std::io::ErrorKind::NotFound { | 28 | if err.kind() == std::io::ErrorKind::NotFound { |
26 | println!("No config file found, creating one"); | 29 | println!("No config file found, creating one"); |
27 | let default_cfg = Cfg { data: String::from("./"), apis: Apis { modrinth: String::from("https://api.modrinth.com/v2/") } }; | 30 | let default_cfg = Cfg { |
31 | data: String::from("./"), | ||
32 | apis: Apis { | ||
33 | modrinth: String::from("https://api.modrinth.com/v2/"), | ||
34 | }, | ||
35 | }; | ||
28 | let mut file = File::create(devdir(configfile.to_str().unwrap()))?; | 36 | let mut file = File::create(devdir(configfile.to_str().unwrap()))?; |
29 | println!("Created config file"); | 37 | println!("Created config file"); |
30 | file.write_all(&toml::to_string(&default_cfg)?.as_bytes())?; | 38 | file.write_all(toml::to_string(&default_cfg)?.as_bytes())?; |
31 | File::open(devdir(configfile.to_str().unwrap()))? | 39 | File::open(devdir(configfile.to_str().unwrap()))? |
32 | } else { | 40 | } else { |
33 | return Err(err.into()); | 41 | return Err(err.into()); |