Add VersionsViewer

This commit is contained in:
Matthias Beyer 2016-07-16 23:36:56 +02:00
parent 42aaf894dc
commit 9c994b2011
2 changed files with 55 additions and 0 deletions

View file

@ -1,2 +1,3 @@
pub mod plain;
pub mod stdout;
pub mod versions;

View file

@ -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()))
}
}