summaryrefslogtreecommitdiffstats
path: root/libimagentryview
diff options
context:
space:
mode:
authorMatthias Beyer <mail@beyermatthias.de>2016-07-16 23:36:56 +0200
committerMatthias Beyer <mail@beyermatthias.de>2016-07-17 01:27:50 +0200
commit9c994b201163ad801434bb19d61c85e5353a0993 (patch)
tree92addf675baf81c2a351957c2d879f4a0eb8ce04 /libimagentryview
parent42aaf894dcbb577f2b9ae8eb16c53c9cea5d3718 (diff)
Add VersionsViewer
Diffstat (limited to 'libimagentryview')
-rw-r--r--libimagentryview/src/builtin/mod.rs1
-rw-r--r--libimagentryview/src/builtin/versions.rs54
2 files changed, 55 insertions, 0 deletions
diff --git a/libimagentryview/src/builtin/mod.rs b/libimagentryview/src/builtin/mod.rs
index 248d8b25..449d9b67 100644
--- a/libimagentryview/src/builtin/mod.rs
+++ b/libimagentryview/src/builtin/mod.rs
@@ -1,2 +1,3 @@
pub mod plain;
pub mod stdout;
+pub mod versions;
diff --git a/libimagentryview/src/builtin/versions.rs b/libimagentryview/src/builtin/versions.rs
new file mode 100644
index 00000000..11439c36
--- /dev/null
+++ b/libimagentryview/src/builtin/versions.rs
@@ -0,0 +1,54 @@
+use libimagstore::store::Entry;
+use libimagstore::store::Store;
+use libimagerror::into::IntoError;
+
+use viewer::Viewer;
+use result::Result;
+use error::ViewErrorKind as VEK;
+
+pub struct VersionsViewer<'a> {
+ store: &'a Store,
+}
+
+impl<'a> VersionsViewer<'a> {
+
+ pub fn new(store: &'a Store) -> VersionsViewer<'a> {
+ VersionsViewer {
+ store: store,
+ }
+ }
+
+}
+
+impl<'a> Viewer for VersionsViewer<'a> {
+
+ fn view_entry(&self, entr: &Entry) -> Result<()> {
+ use glob::glob;
+
+ entr.get_location()
+ .clone()
+ .storified(self.store)
+ .to_str()
+ .and_then(|s| s.split("~").next())
+ .map(|component| {
+ glob(&format!("{}~*", component)[..])
+ .map_err(|_| VEK::PatternError.into_error())
+ .and_then(|paths| {
+ for entry in paths {
+ let p = match entry {
+ Err(_) => return Err(VEK::GlobError.into_error()),
+ Ok(p) => p,
+ };
+ let p = p.file_name()
+ .and_then(|s| s.to_str())
+ .unwrap(); // TODO
+ println!("{}", p);
+ };
+ Ok(())
+ })
+ })
+ .unwrap_or(Err(VEK::PatternBuildingError.into_error()))
+ }
+
+}
+