Replace config crate with toml

config crate was not really needed
embed
Manos Pitsidianakis 2019-08-25 14:14:54 +03:00
parent b474b44b10
commit 02b0f69e14
Signed by: Manos Pitsidianakis
GPG Key ID: 73627C2F690DF710
2 changed files with 12 additions and 15 deletions

View File

@ -10,7 +10,7 @@ xdg = "2.1.0" # >:c
serde = "1.0.71"
serde_derive = "1.0.71"
serde_json = "1.0"
config = { git = "https://github.com/meli/config-rs", version = "*" }
toml = "0.5.3"
chan = "0.1.21"
chan-signal = "0.3.1"
fnv = "1.0.3" # >:c

View File

@ -20,8 +20,8 @@
*/
extern crate bincode;
extern crate config;
extern crate serde;
extern crate toml;
extern crate xdg;
pub mod mailer;
@ -31,7 +31,6 @@ pub mod shortcuts;
pub mod accounts;
pub use self::accounts::Account;
use self::config::{Config, File, FileFormat};
pub use self::mailer::*;
pub use self::shortcuts::*;
@ -45,8 +44,8 @@ use melib::error::*;
use self::serde::{de, Deserialize, Deserializer};
use std::collections::HashMap;
use std::env;
use std::fs::OpenOptions;
use std::io::{self, BufRead, Write};
use std::fs::{File, OpenOptions};
use std::io::{self, BufRead, Read, Write};
use std::path::PathBuf;
#[macro_export]
@ -338,19 +337,17 @@ impl FileSettings {
}
}
}
let mut s = Config::new();
if s.merge(File::new(config_path.to_str().unwrap(), FileFormat::Toml))
.is_err()
{
eprintln!("Config file contains errors.");
let mut file = File::open(config_path.to_str().unwrap())?;
let mut contents = String::new();
file.read_to_string(&mut contents)?;
let s = toml::from_str(&contents);
if let Err(e) = s {
eprintln!("Config file contains errors: {}", e.to_string());
std::process::exit(1);
}
/* No point in returning without a config file. */
match s.try_into() {
Ok(v) => Ok(v),
Err(e) => Err(MeliError::new(e.to_string())),
}
Ok(s.unwrap())
}
}