use std::env; use std::fs::File; use std::io::Read; extern crate tenquestionmarks; use tenquestionmarks::Tenquestionmarks; extern crate toml; use toml::Parser; fn main () { let configFileName = env::args().nth(1).unwrap_or("tenquestionmarks.toml".into()); match File::open(&configFileName) { Ok(mut file) => { let mut contents = String::new(); match file.read_to_string(&mut contents) { Ok(value) => { let mut parser = Parser::new(&contents); match parser.parse() { Some(configuration) => { println!("Loaded configuration from: {}", configFileName); match Tenquestionmarks::from_configuration(configuration) { Ok(tqm) => { println!("tenquestionmarks initialized successfully"); tqm.run(); }, Err(e) => println!("Failed to initialize tenquestionmarks: {:?}", e) } }, None => { println!("Failed to parse config file {}: {:?}. Config file must be a valid TOML file.", configFileName, parser.errors); } } }, Err(e) => { println!("Failed to open config file {}: {:?}", configFileName, e); } } }, Err(e) => { println!("Failed to open config file! Please specify path to a config file."); } } }