diff options
author | fx <[email protected]> | 2023-04-23 14:13:03 +0200 |
---|---|---|
committer | fx <[email protected]> | 2023-04-23 14:13:03 +0200 |
commit | 4300ad2eb05dddfa4274e04b204f2ad28c87da05 (patch) | |
tree | a2fd059e3aefff812d0d25e23fc85203dc9d122a /src/config.rs | |
parent | 2711f05669e353fbf452156d54855e9ba454f4a8 (diff) | |
parent | 64958cc9ff0858dbf068625e35b8d5dae249d4a4 (diff) | |
download | modlist-4300ad2eb05dddfa4274e04b204f2ad28c87da05.tar modlist-4300ad2eb05dddfa4274e04b204f2ad28c87da05.tar.gz modlist-4300ad2eb05dddfa4274e04b204f2ad28c87da05.zip |
Merge pull request 'clap' (#1) from clap into master
Reviewed-on: http://raspberrypi.fritz.box:7920/fx/modlist/pulls/1
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()); |