From a4ed13e46fcef39d53126b3dc11d4f3705237b60 Mon Sep 17 00:00:00 2001 From: Till Hoeppner Date: Fri, 12 Jun 2015 20:08:54 +0200 Subject: Start CLI --- src/main.rs | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/main.rs b/src/main.rs index a1f7f26..13cc86f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -26,7 +26,7 @@ extern crate log; extern crate env_logger; use std::fs::File; -use std::io::{ self, BufReader }; +use std::io::{ self, Read, BufRead, BufReader, Write }; use std::str::FromStr; use docopt::Docopt; @@ -35,6 +35,7 @@ use chrono::offset::fixed::FixedOffset; use chrono::naive::date::NaiveDate; use ilc::context::Context; +use ilc::event::Event; use ilc::format::{ self, Encode, Decode }; static USAGE: &'static str = r#" @@ -67,6 +68,8 @@ struct Args { cmd_parse: bool, cmd_convert: bool, arg_file: Vec, + arg_informat: Option, + arg_outformat: Option, flag_help: bool, flag_version: bool, flag_date: Option, @@ -113,11 +116,19 @@ fn main() { if args.cmd_convert { let stdin = io::stdin(); - let mut parser = format::energymech::Energymech; - let formatter = format::binary::Binary; - - for e in parser.decode(&context, stdin.lock()) { - drop(formatter.encode(&context, io::stdout(), &e.unwrap())) + let mut parser: &mut Decode<&mut BufRead, Box>> = match args.arg_informat.map(|s| s.as_ref()) { + Some("energymech") => &mut format::energymech::Energymech, + Some("weechat3") => &mut format::weechat3::Weechat3, + Some("binary") => &mut format::binary::Binary + }; + let formatter: &Encode<&mut Write> = match args.arg_outformat.map(|s| s.as_ref()) { + Some("energymech") => &format::energymech::Energymech, + Some("weechat3") => &format::weechat3::Weechat3, + Some("binary") => &format::binary::Binary + }; + + for e in parser.decode(&context, &mut stdin.lock()) { + drop(formatter.encode(&context, &mut io::stdout(), &e.unwrap())) } } } -- cgit v1.2.3