aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTill Hoeppner2015-06-12 20:08:54 +0200
committerTill Hoeppner2015-06-12 20:08:54 +0200
commita4ed13e46fcef39d53126b3dc11d4f3705237b60 (patch)
tree390542ba41554f665e1d3c07a7b6027c74253777
parentf4d8b1a521c567ccc8e2470299287b063e0d5926 (diff)
downloadilc-a4ed13e46fcef39d53126b3dc11d4f3705237b60.tar.gz
ilc-a4ed13e46fcef39d53126b3dc11d4f3705237b60.tar.xz
ilc-a4ed13e46fcef39d53126b3dc11d4f3705237b60.zip
Start CLI
-rw-r--r--src/main.rs23
1 files changed, 17 insertions, 6 deletions
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<String>,
+ arg_informat: Option<String>,
+ arg_outformat: Option<String>,
flag_help: bool,
flag_version: bool,
flag_date: Option<String>,
@@ -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<Iterator<Item=Event>>> = 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()))
}
}
}