Read input files

This commit is contained in:
Jake Howard 2017-07-20 09:14:48 +01:00
parent 5953f2b76b
commit 54d827fa74
Signed by: jake
GPG key ID: 57AFB45680EDD477
4 changed files with 28 additions and 4 deletions

View file

@ -11,9 +11,9 @@ pub mod validate_types;
#[derive(Debug, Serialize, Deserialize, Default)] #[derive(Debug, Serialize, Deserialize, Default)]
pub struct Config { pub struct Config {
input: Vec<PathBuf>, pub input: Vec<PathBuf>,
output: HashMap<String, PathBuf>, pub output: HashMap<String, PathBuf>,
title: String pub title: String
} }
impl Config { impl Config {

13
src/input.rs Normal file
View file

@ -0,0 +1,13 @@
use std::fs::File;
use std::io::Read;
use std::path::PathBuf;
pub fn read_input_files(files: Vec<PathBuf>) -> 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;
}

View file

@ -8,6 +8,8 @@ extern crate serde_yaml;
mod args; mod args;
mod config; mod config;
mod process;
mod input;
#[cfg(test)] #[cfg(test)]
mod tests; mod tests;
@ -15,6 +17,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" {
println!("{:?}", config::get_config()); let config = config::get_config();
process::build(config);
} }
} }

8
src/process.rs Normal file
View file

@ -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);
}