[No-auto] bin/core/store: Fix Clippy warnings
Signed-off-by: flip1995 <hello@philkrones.com> Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
This commit is contained in:
parent
5b0817bcb6
commit
a2d3a8cffc
3 changed files with 26 additions and 31 deletions
|
@ -31,24 +31,22 @@ use libimagerror::exit::ExitUnwrap;
|
|||
use libimagutil::debug_result::*;
|
||||
|
||||
pub fn retrieve(rt: &Runtime) {
|
||||
rt.cli()
|
||||
.subcommand_matches("retrieve")
|
||||
.map(|scmd| {
|
||||
// unwrap() is safe as arg is required
|
||||
let id = scmd.value_of("id").unwrap();
|
||||
let path = PathBuf::from(id);
|
||||
let path = StoreId::new(path).map_err_trace_exit_unwrap();
|
||||
debug!("path = {:?}", path);
|
||||
if let Some(scmd) = rt.cli().subcommand_matches("retrieve") {
|
||||
// unwrap() is safe as arg is required
|
||||
let id = scmd.value_of("id").unwrap();
|
||||
let path = PathBuf::from(id);
|
||||
let path = StoreId::new(path).map_err_trace_exit_unwrap();
|
||||
debug!("path = {:?}", path);
|
||||
|
||||
rt.store()
|
||||
.retrieve(path.clone())
|
||||
.map(|e| print_entry(rt, scmd, e))
|
||||
.map_dbg_str("No entry")
|
||||
.map_dbg(|e| format!("{:?}", e))
|
||||
.map_err_trace_exit_unwrap();
|
||||
rt.store()
|
||||
.retrieve(path.clone())
|
||||
.map(|e| print_entry(rt, scmd, e))
|
||||
.map_dbg_str("No entry")
|
||||
.map_dbg(|e| format!("{:?}", e))
|
||||
.map_err_trace_exit_unwrap();
|
||||
|
||||
rt.report_touched(&path).unwrap_or_exit();
|
||||
});
|
||||
rt.report_touched(&path).unwrap_or_exit();
|
||||
}
|
||||
}
|
||||
|
||||
pub fn print_entry(rt: &Runtime, scmd: &ArgMatches, e: FileLockEntry) {
|
||||
|
|
|
@ -39,11 +39,10 @@ pub fn update(rt: &Runtime) {
|
|||
{
|
||||
let e = locked_e.deref_mut();
|
||||
|
||||
scmd.value_of("content")
|
||||
.map(|new_content| {
|
||||
*e.get_content_mut() = String::from(new_content);
|
||||
debug!("New content set");
|
||||
});
|
||||
if let Some(new_content) = scmd.value_of("content") {
|
||||
*e.get_content_mut() = String::from(new_content);
|
||||
debug!("New content set");
|
||||
}
|
||||
|
||||
*e.get_header_mut() = build_toml_header(scmd, e.get_header().clone());
|
||||
debug!("New header set");
|
||||
|
|
|
@ -40,10 +40,8 @@ pub fn build_toml_header(matches: &ArgMatches, mut header: Value) -> Value {
|
|||
let (key, value) = tpl.into();
|
||||
debug!("Splitting: {:?}", key);
|
||||
let mut split = key.split('.');
|
||||
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),
|
||||
_ => { }
|
||||
if let (Some(cur), &mut Value::Table(ref mut hdr)) = (split.next(), &mut header) {
|
||||
insert_key_into(String::from(cur), &mut split, Cow::Owned(value), hdr);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -58,27 +56,27 @@ fn insert_key_into<'a>(current: String,
|
|||
map: &mut Map<String, Value>) {
|
||||
let next = rest_path.next();
|
||||
|
||||
if next.is_none() {
|
||||
debug!("Inserting into {:?} = {:?}", current, value);
|
||||
map.insert(current, parse_value(value));
|
||||
} else {
|
||||
if let Some(next) = next {
|
||||
debug!("Inserting into {:?} ... = {:?}", current, value);
|
||||
match map.entry(current) {
|
||||
Entry::Occupied(ref mut e) => {
|
||||
match *e.get_mut() {
|
||||
Value::Table(ref mut t) => {
|
||||
insert_key_into(String::from(next.unwrap()), rest_path, value, t);
|
||||
insert_key_into(String::from(next), rest_path, value, t);
|
||||
},
|
||||
_ => unreachable!(),
|
||||
}
|
||||
},
|
||||
Entry::Vacant(v) => { v.insert(Value::Table( {
|
||||
let mut submap = Map::new();
|
||||
insert_key_into(String::from(next.unwrap()), rest_path, value, &mut submap);
|
||||
insert_key_into(String::from(next), rest_path, value, &mut submap);
|
||||
debug!("Inserting submap = {:?}", submap);
|
||||
submap }));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
debug!("Inserting into {:?} = {:?}", current, value);
|
||||
map.insert(current, parse_value(value));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue