summaryrefslogtreecommitdiffstats
path: root/imag-store
diff options
context:
space:
mode:
authorMatthias Beyer <mail@beyermatthias.de>2016-11-17 12:41:37 +0100
committerMatthias Beyer <mail@beyermatthias.de>2017-02-05 13:10:39 +0100
commit7b3f28eb0aaffd8c2429dfc01cadf6c54d2070e6 (patch)
tree80a60db8c400f6035b585ea42318c86c4eb7c404 /imag-store
parent36dfee812f2cf8c453d43338ba47f78734d8c99c (diff)
imag-store: Use TomlValueExt in replace for EntryHeader
Also, do not build empty TOML but use Entry::build_default_header()
Diffstat (limited to 'imag-store')
-rw-r--r--imag-store/src/create.rs13
-rw-r--r--imag-store/src/retrieve.rs4
-rw-r--r--imag-store/src/util.rs20
3 files changed, 16 insertions, 21 deletions
diff --git a/imag-store/src/create.rs b/imag-store/src/create.rs
index cfdbd01b..e015595f 100644
--- a/imag-store/src/create.rs
+++ b/imag-store/src/create.rs
@@ -28,10 +28,10 @@ use std::io::stderr;
use std::process::exit;
use clap::ArgMatches;
+use toml::Value;
use libimagrt::runtime::Runtime;
use libimagstore::store::Entry;
-use libimagstore::store::EntryHeader;
use libimagstore::storeid::StoreId;
use libimagerror::trace::trace_error_exit;
use libimagutil::debug_result::*;
@@ -70,10 +70,11 @@ pub fn create(rt: &Runtime) {
.or_else(|_| create_with_content_and_header(rt,
&path,
String::new(),
- EntryHeader::new()))
+ Entry::default_header()))
} else {
debug!("Creating entry");
- create_with_content_and_header(rt, &path, String::new(), EntryHeader::new())
+ create_with_content_and_header(rt, &path, String::new(),
+ Entry::default_header())
}
.unwrap_or_else(|e| {
error!("Error building Entry");
@@ -100,8 +101,8 @@ fn create_from_cli_spec(rt: &Runtime, matches: &ArgMatches, path: &StoreId) -> R
debug!("Got content with len = {}", content.len());
let header = matches.subcommand_matches("entry")
- .map_or_else(EntryHeader::new,
- |entry_matches| build_toml_header(entry_matches, EntryHeader::new()));
+ .map_or_else(|| Entry::default_header(),
+ |entry_matches| build_toml_header(entry_matches, Entry::default_header()));
create_with_content_and_header(rt, path, content, header)
}
@@ -138,7 +139,7 @@ fn create_from_source(rt: &Runtime, matches: &ArgMatches, path: &StoreId) -> Res
fn create_with_content_and_header(rt: &Runtime,
path: &StoreId,
content: String,
- header: EntryHeader) -> Result<()>
+ header: Value) -> Result<()>
{
debug!("Creating entry with content at {:?}", path);
rt.store()
diff --git a/imag-store/src/retrieve.rs b/imag-store/src/retrieve.rs
index 4d17e817..19c85b16 100644
--- a/imag-store/src/retrieve.rs
+++ b/imag-store/src/retrieve.rs
@@ -20,7 +20,6 @@
use std::path::PathBuf;
use clap::ArgMatches;
-use toml::Value;
use libimagstore::store::FileLockEntry;
use libimagstore::storeid::StoreId;
@@ -70,8 +69,7 @@ pub fn print_entry(rt: &Runtime, scmd: &ArgMatches, e: FileLockEntry) {
unimplemented!()
} else {
debug!("Printing header as TOML...");
- // We have to Value::Table() for Display
- println!("{}", Value::Table(e.get_header().clone().into()))
+ println!("{}", e.get_header())
}
}
diff --git a/imag-store/src/util.rs b/imag-store/src/util.rs
index 8e7002c9..5da04666 100644
--- a/imag-store/src/util.rs
+++ b/imag-store/src/util.rs
@@ -24,13 +24,11 @@ use std::str::Split;
use clap::ArgMatches;
use toml::Value;
-use libimagstore::store::EntryHeader;
use libimagutil::key_value_split::IntoKeyValue;
-pub fn build_toml_header(matches: &ArgMatches, header: EntryHeader) -> EntryHeader {
+pub fn build_toml_header(matches: &ArgMatches, mut header: Value) -> Value {
debug!("Building header from cli spec");
if let Some(headerspecs) = matches.values_of("header") {
- let mut main = header.into();
let kvs = headerspecs.into_iter()
.filter_map(|hs| {
debug!("- Processing: '{}'", hs);
@@ -42,18 +40,16 @@ pub fn build_toml_header(matches: &ArgMatches, header: EntryHeader) -> EntryHead
let (key, value) = tpl.into();
debug!("Splitting: {:?}", key);
let mut split = key.split('.');
- let current = split.next();
- if current.is_some() {
- insert_key_into(String::from(current.unwrap()), &mut split, Cow::Owned(value), &mut main);
+ match (split.next(), &mut header) {
+ (Some(cur), &mut Value::Table(ref mut hdr)) =>
+ insert_key_into(String::from(cur), &mut split, Cow::Owned(value), hdr),
+ _ => { }
}
}
-
- debug!("Header = {:?}", main);
- EntryHeader::from(main)
- } else {
- debug!("Header = {:?}", header);
- header
}
+
+ debug!("Header = {:?}", header);
+ header
}
fn insert_key_into<'a>(current: String,