summaryrefslogtreecommitdiffstats
path: root/imag-view
diff options
context:
space:
mode:
authorMatthias Beyer <mail@beyermatthias.de>2016-02-24 13:45:37 +0100
committerMatthias Beyer <mail@beyermatthias.de>2016-03-11 16:21:33 +0100
commitd99d38bf8e963942280bc376399bcc1eec4468e3 (patch)
tree10976638e5f1169f132945f50750d1f41199d4d2 /imag-view
parentd02ac8bd8846507cf2c38cbfdbd3f567b8abbaec (diff)
Implement entry loading
Diffstat (limited to 'imag-view')
-rw-r--r--imag-view/src/main.rs37
-rw-r--r--imag-view/src/viewer/mod.rs7
2 files changed, 37 insertions, 7 deletions
diff --git a/imag-view/src/main.rs b/imag-view/src/main.rs
index 4692337e..137d57b6 100644
--- a/imag-view/src/main.rs
+++ b/imag-view/src/main.rs
@@ -15,7 +15,9 @@ use clap::ArgMatches;
use libimagrt::runtime::Runtime;
use libimagstore::store::Entry;
+use libimagstore::store::FileLockEntry;
use libimagstore::store::Result as StoreResult;
+use libimagstore::storeid::StoreId;
use libimagutil::trace::trace_error;
mod ui;
@@ -69,7 +71,7 @@ fn main() {
let scmd = scmd.unwrap();
let viewer = build_viewer(scmd);
- let entry = load_entry(entry_id, entry_version);
+ let entry = load_entry(entry_id, entry_version, &rt);
if entry.is_err() {
trace_error(&entry.err().unwrap());
exit(1);
@@ -88,8 +90,37 @@ fn main() {
}
}
-fn load_entry(id: &str, version: Option<&str>) -> StoreResult<Entry> {
- unimplemented!()
+// TODO: This is a shameless adaption of imag-store/src/util.rs
+fn load_entry<'a>(id: &str,
+ version: Option<&str>,
+ rt: &'a Runtime)
+ -> StoreResult<FileLockEntry<'a>>
+{
+ use std::ops::Deref;
+
+ debug!("Checking path element for version");
+
+ let version = {
+ version.unwrap_or_else(|| {
+ id.split("~").last().unwrap_or_else(|| {
+ warn!("No version");
+ exit(1);
+ })
+ })
+ };
+
+ debug!("Building path from {:?} and {:?}", id, version);
+ let mut path = rt.store().path().clone();
+
+ if id.chars().next() == Some('/') {
+ path.push(format!("{}~{}", &id[1..id.len()], version));
+ } else {
+ path.push(format!("{}~{}", id, version));
+ }
+
+ // the above is the adaption...
+
+ rt.store().retrieve(path)
}
fn view_versions_of(id: &str, rt: &Runtime) {
diff --git a/imag-view/src/viewer/mod.rs b/imag-view/src/viewer/mod.rs
index a12d1b36..f7e3653f 100644
--- a/imag-view/src/viewer/mod.rs
+++ b/imag-view/src/viewer/mod.rs
@@ -1,10 +1,9 @@
pub mod stdout;
-use libimagstore::store::Entry;
+use libimagstore::store::FileLockEntry;
-#[derive(Debug)]
-pub struct ViewInformation {
- pub entry: Entry,
+pub struct ViewInformation<'a> {
+ pub entry: FileLockEntry<'a>,
pub view_header: bool,
pub view_content: bool,
pub view_copy: bool,