aboutsummaryrefslogtreecommitdiff
path: root/cli
diff options
context:
space:
mode:
authorTill Höppner2016-03-02 12:57:36 +0100
committerTill Höppner2016-03-02 12:57:36 +0100
commita4db0628a0377b39be02f0e83832b0c3527933e1 (patch)
tree375e33b2942b6374e352b554d7202664812ddf2f /cli
parent52d4c29f5bce85abadeb9fd394f55caf488b37f3 (diff)
downloadilc-0.3.tar.gz
ilc-0.3.tar.xz
ilc-0.3.zip
Merging of any number of logsv0.3.0v0.3
Diffstat (limited to 'cli')
-rw-r--r--cli/Cargo.toml10
-rw-r--r--cli/src/lib.rs60
2 files changed, 52 insertions, 18 deletions
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<BufRead> {
open_files(gather_input(self.0))
}
+
+ pub fn inputs(&self) -> Vec<Box<BufRead>> {
+ gather_input(self.0)
+ .iter()
+ .map(|path| {
+ Box::new(BufReader::new(File::open(path)
+ .unwrap_or_else(|e| {
+ error(Box::new(e))
+ }))) as Box<BufRead>
+ })
+ .collect()
+ }
+
pub fn output(&self) -> Box<Write> {
open_output(self.0)
}
+
pub fn decoder(&self) -> Box<Decode> {
force_decoder(self.0.value_of("format").or(self.0.value_of("input_format")))
}
+
+ /* pub fn decoders(&self) -> Vec<Box<Decode>> {
+ * self.0
+ * .value_of("format")
+ * .into_iter()
+ * .chain(self.0
+ * .values_of("input_formats")
+ * .map(|i| Box::new(i) as Box<Iterator<Item = _>>)
+ * .unwrap_or(Box::new(iter::empty()) as Box<Iterator<Item = _>>))
+ * .map(Option::Some)
+ * .map(force_decoder)
+ * .collect()
+ * } */
+
pub fn encoder(&self) -> Box<Encode> {
force_encoder(self.0.value_of("format").or(self.0.value_of("output_format")))
}