From 54d827fa744c8a91b6e12b6f09c270a73c4262c7 Mon Sep 17 00:00:00 2001 From: Jake Howard Date: Thu, 20 Jul 2017 09:14:48 +0100 Subject: [PATCH] Read input files --- src/config/mod.rs | 6 +++--- src/input.rs | 13 +++++++++++++ src/main.rs | 5 ++++- src/process.rs | 8 ++++++++ 4 files changed, 28 insertions(+), 4 deletions(-) create mode 100644 src/input.rs create mode 100644 src/process.rs diff --git a/src/config/mod.rs b/src/config/mod.rs index 27e1025..9b17854 100644 --- a/src/config/mod.rs +++ b/src/config/mod.rs @@ -11,9 +11,9 @@ pub mod validate_types; #[derive(Debug, Serialize, Deserialize, Default)] pub struct Config { - input: Vec, - output: HashMap, - title: String + pub input: Vec, + pub output: HashMap, + pub title: String } impl Config { diff --git a/src/input.rs b/src/input.rs new file mode 100644 index 0000000..a8d7e8d --- /dev/null +++ b/src/input.rs @@ -0,0 +1,13 @@ +use std::fs::File; +use std::io::Read; +use std::path::PathBuf; + + +pub fn read_input_files(files: Vec) -> String { + let mut input = String::new(); + for input_file_path in files.iter() { + let mut input_file = File::open(input_file_path).expect("Unable to open file"); + input_file.read_to_string(&mut input).expect("Failed to read file"); + } + return input; +} diff --git a/src/main.rs b/src/main.rs index 7cfef6c..28b5172 100644 --- a/src/main.rs +++ b/src/main.rs @@ -8,6 +8,8 @@ extern crate serde_yaml; mod args; mod config; +mod process; +mod input; #[cfg(test)] mod tests; @@ -15,6 +17,7 @@ mod tests; fn main() { let args = args::get_matches(); if args.subcommand_name().unwrap() == "build" { - println!("{:?}", config::get_config()); + let config = config::get_config(); + process::build(config); } } diff --git a/src/process.rs b/src/process.rs new file mode 100644 index 0000000..363e959 --- /dev/null +++ b/src/process.rs @@ -0,0 +1,8 @@ +use input::read_input_files; +use config::Config; + + +pub fn build(config: Config) { + let input = read_input_files(config.input); + println!("{}", input); +}