imag-store: Use TomlValueExt in replace for EntryHeader
Also, do not build empty TOML but use Entry::build_default_header()
This commit is contained in:
parent
36dfee812f
commit
7b3f28eb0a
3 changed files with 16 additions and 21 deletions
|
@ -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()
|
||||
|
|
|
@ -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())
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Reference in a new issue