Added function for reading server config dirs. It's not complete yet.
This commit is contained in:
parent
716584841e
commit
78d5bafae3
2 changed files with 26 additions and 8 deletions
|
@ -16,16 +16,34 @@
|
|||
*/
|
||||
|
||||
use std::{
|
||||
path::Path,
|
||||
path::PathBuf,
|
||||
io::Read,
|
||||
fs::read_dir,
|
||||
};
|
||||
use toml::value::Value;
|
||||
|
||||
fn parse_server_dir(mut config: Value, server_config_path: PathBuf)
|
||||
-> Result<Value, Box<dyn std::error::Error>> {
|
||||
let mut config = config.as_table_mut().unwrap().clone();
|
||||
if server_config_path.is_dir() {
|
||||
for entry in read_dir(server_config_path)? {
|
||||
let entry = entry?;
|
||||
match entry.file_name().to_str().ok_or("Could not read file name")? {
|
||||
"config.toml" => (),
|
||||
"clients.toml" => (),
|
||||
"channels.toml" => (),
|
||||
_ => (),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Ok(Value::from(config))
|
||||
}
|
||||
|
||||
/// parses a toml config file and sets some default values
|
||||
/// if the corresponding fields are not set.
|
||||
// TODO: Document config file options once they are stable.
|
||||
pub fn get_main_config(config_path: &Path)
|
||||
pub fn get_main_config(config_path: PathBuf)
|
||||
-> Result<Value, Box<dyn std::error::Error>> {
|
||||
|
||||
// I once read that this multiple let style
|
||||
|
@ -55,14 +73,14 @@ pub fn get_main_config(config_path: &Path)
|
|||
Ok(Value::from(config))
|
||||
}
|
||||
|
||||
pub fn get_server_config (config: Value, config_path: &Path)
|
||||
pub fn get_server_config(mut config: Value, config_path: PathBuf)
|
||||
-> Result<Value, Box<dyn std::error::Error>> {
|
||||
if config_path.is_dir() {
|
||||
for entry in read_dir(config_path)? {
|
||||
let entry = entry?;
|
||||
let server_path = entry.path();
|
||||
if server_path.is_dir(){
|
||||
config = server_config_helper(config, server_path)?;
|
||||
config = parse_server_dir(config, server_path)?;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,7 +21,7 @@ pub mod config;
|
|||
use std::{
|
||||
format,
|
||||
env::args,
|
||||
path::Path,
|
||||
path::PathBuf,
|
||||
collections::VecDeque,
|
||||
};
|
||||
use irc_proto::command::{
|
||||
|
@ -155,14 +155,14 @@ fn main() {
|
|||
let mut config;
|
||||
|
||||
match config_path {
|
||||
Some(p) => config = config::get_main_config(&Path::from(p))
|
||||
Some(p) => config = config::get_main_config(PathBuf::from(p))
|
||||
.expect("Could not get config"),
|
||||
None => config = config::get_main_config(&Path::from("/etc/Mention2Mail/config.toml"))
|
||||
None => config = config::get_main_config(PathBuf::from("/etc/Mention2Mail/config.toml"))
|
||||
.expect("Could not get default config in /etc/Mention2Mail/default.toml"),
|
||||
}
|
||||
|
||||
match server_conf_path {
|
||||
Some(p) => config = config::get_server_config(config, p)
|
||||
Some(p) => config = config::get_server_config(config, PathBuf::from(p))
|
||||
.expect("Could not get server config."),
|
||||
None => (),
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue