From a4db0628a0377b39be02f0e83832b0c3527933e1 Mon Sep 17 00:00:00 2001 From: Till Höppner Date: Wed, 2 Mar 2016 12:57:36 +0100 Subject: Merging of any number of logs --- cli/Cargo.toml | 10 +++++----- cli/src/lib.rs | 60 +++++++++++++++++++++++++++++++++++++++++++++------------- 2 files changed, 52 insertions(+), 18 deletions(-) (limited to 'cli') diff --git a/cli/Cargo.toml b/cli/Cargo.toml index e984319..8e66b7e 100644 --- a/cli/Cargo.toml +++ b/cli/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "ilc-cli" -version = "0.1.1" +version = "0.1.2" description = "IRC log converter/collector/cruncher" homepage = "https://github.com/tilpner/ilc" license = "Apache-2.0" @@ -16,7 +16,7 @@ clap = "2.1.2" chrono = "0.2.19" env_logger = "0.3.2" glob = "0.2.10" -ilc-base = "0.1.0" -ilc-ops = "0.1.0" -ilc-format-weechat = { optional = true, version = "0.1.0" } -ilc-format-energymech = { optional = true, version = "0.1.0" } +ilc-base = "~0.2" +ilc-ops = "~0.1" +ilc-format-weechat = { optional = true, version = "~0.2" } +ilc-format-energymech = { optional = true, version = "~0.2" } diff --git a/cli/src/lib.rs b/cli/src/lib.rs index 40bc2e7..9469cfb 100644 --- a/cli/src/lib.rs +++ b/cli/src/lib.rs @@ -47,6 +47,10 @@ mod chain; pub fn main() { env_logger::init().unwrap(); + if option_env!("FUSE").is_some() { + info!("Compiled with FUSEs") + } + let args = App::new("ilc") .version(crate_version!()) .setting(AppSettings::GlobalVersion) @@ -181,21 +185,22 @@ pub fn main() { &*e.encoder()) } ("merge", Some(args)) => { - // TODO: avoid (de-)serialization to weechat let e = Environment(&args); - let (ctx, i, d, o, e) = (&e.context(), - &mut e.input(), - &mut *e.decoder(), - &mut *e.output(), - &*e.encoder()); - let mut buffer = Vec::new(); - match sort::sort(ctx, i, d, &mut buffer, &Weechat) { - Err(e) => error(Box::new(e)), - _ => (), - } - let mut read = io::Cursor::new(&buffer); - dedup::dedup(ctx, &mut read, &mut Weechat, o, e) + let mut inputs = e.inputs(); + // let mut decoders = e.decoders(); + + let borrowed_inputs = inputs.iter_mut() + .map(|a| a as &mut BufRead) + .collect(); + // let borrowed_decoders = decoders.iter_mut() + // .map(|a| &mut **a as &mut Decode) + // .collect(); + merge::merge(&e.context(), + borrowed_inputs, + &mut *e.decoder(), + &mut *e.output(), + &*e.encoder()) } (sc, _) if !sc.is_empty() => panic!("Unimplemented subcommand `{}`, this is a bug", sc), _ => die("No command specified"), @@ -272,15 +277,44 @@ impl<'a> Environment<'a> { pub fn context(&self) -> Context { build_context(self.0) } + pub fn input(&self) -> Box { open_files(gather_input(self.0)) } + + pub fn inputs(&self) -> Vec> { + gather_input(self.0) + .iter() + .map(|path| { + Box::new(BufReader::new(File::open(path) + .unwrap_or_else(|e| { + error(Box::new(e)) + }))) as Box + }) + .collect() + } + pub fn output(&self) -> Box { open_output(self.0) } + pub fn decoder(&self) -> Box { force_decoder(self.0.value_of("format").or(self.0.value_of("input_format"))) } + + /* pub fn decoders(&self) -> Vec> { + * self.0 + * .value_of("format") + * .into_iter() + * .chain(self.0 + * .values_of("input_formats") + * .map(|i| Box::new(i) as Box>) + * .unwrap_or(Box::new(iter::empty()) as Box>)) + * .map(Option::Some) + * .map(force_decoder) + * .collect() + * } */ + pub fn encoder(&self) -> Box { force_encoder(self.0.value_of("format").or(self.0.value_of("output_format"))) } -- cgit v1.2.3