Construct config with basic defaults
This commit is contained in:
parent
c83d847051
commit
6d389c6fbd
3 changed files with 23 additions and 8 deletions
|
@ -1,24 +1,31 @@
|
||||||
use serde_yaml;
|
use serde_yaml;
|
||||||
|
use serde_yaml::Value;
|
||||||
|
|
||||||
pub mod read;
|
pub mod read;
|
||||||
pub mod validate;
|
pub mod validate;
|
||||||
pub mod consts;
|
pub mod consts;
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize)]
|
#[derive(Debug, Serialize, Deserialize, Default)]
|
||||||
pub struct Config {
|
pub struct Config {
|
||||||
foo: String
|
raw: String,
|
||||||
|
input: Vec<String>,
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Config {
|
impl Config {
|
||||||
fn new(raw: String) -> Config {
|
fn new(raw: String) -> Config {
|
||||||
return serde_yaml::from_str(&raw).unwrap();
|
let raw_conf: Value = serde_yaml::from_str(&raw).unwrap();
|
||||||
|
return Config {
|
||||||
|
raw: raw,
|
||||||
|
input: read::get_inputs(raw_conf),
|
||||||
|
..Default::default()
|
||||||
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
pub fn get_config() {
|
pub fn get_config() -> Config {
|
||||||
let config_str = read::read();
|
let config_str = read::read();
|
||||||
let config = Config::new(config_str);
|
|
||||||
println!("{:?}", config);
|
return Config::new(config_str);
|
||||||
validate::validate(config);
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,7 @@ use std::env::current_dir;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
use std::io::Read;
|
use std::io::Read;
|
||||||
|
use serde_yaml::Value;
|
||||||
|
|
||||||
use config::consts;
|
use config::consts;
|
||||||
|
|
||||||
|
@ -19,3 +20,9 @@ pub fn read() -> String {
|
||||||
config_file.read_to_string(&mut contents).expect("Failed to read file");
|
config_file.read_to_string(&mut contents).expect("Failed to read file");
|
||||||
return contents;
|
return contents;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
pub fn get_inputs(conf: Value) -> Vec<String> {
|
||||||
|
let input_values = conf.get("input").unwrap().as_sequence().unwrap().to_vec();
|
||||||
|
return input_values.into_iter().map(|x| x.as_str().unwrap().to_string()).collect();
|
||||||
|
}
|
||||||
|
|
|
@ -13,6 +13,7 @@ mod tests;
|
||||||
fn main() {
|
fn main() {
|
||||||
let args = args::get_matches();
|
let args = args::get_matches();
|
||||||
if args.subcommand_name().unwrap() == "build" {
|
if args.subcommand_name().unwrap() == "build" {
|
||||||
config::get_config();
|
println!("{:?}", config::get_config());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Reference in a new issue