[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::*;
|
use libimagutil::debug_result::*;
|
||||||
|
|
||||||
pub fn retrieve(rt: &Runtime) {
|
pub fn retrieve(rt: &Runtime) {
|
||||||
rt.cli()
|
if let Some(scmd) = rt.cli().subcommand_matches("retrieve") {
|
||||||
.subcommand_matches("retrieve")
|
// unwrap() is safe as arg is required
|
||||||
.map(|scmd| {
|
let id = scmd.value_of("id").unwrap();
|
||||||
// unwrap() is safe as arg is required
|
let path = PathBuf::from(id);
|
||||||
let id = scmd.value_of("id").unwrap();
|
let path = StoreId::new(path).map_err_trace_exit_unwrap();
|
||||||
let path = PathBuf::from(id);
|
debug!("path = {:?}", path);
|
||||||
let path = StoreId::new(path).map_err_trace_exit_unwrap();
|
|
||||||
debug!("path = {:?}", path);
|
|
||||||
|
|
||||||
rt.store()
|
rt.store()
|
||||||
.retrieve(path.clone())
|
.retrieve(path.clone())
|
||||||
.map(|e| print_entry(rt, scmd, e))
|
.map(|e| print_entry(rt, scmd, e))
|
||||||
.map_dbg_str("No entry")
|
.map_dbg_str("No entry")
|
||||||
.map_dbg(|e| format!("{:?}", e))
|
.map_dbg(|e| format!("{:?}", e))
|
||||||
.map_err_trace_exit_unwrap();
|
.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) {
|
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();
|
let e = locked_e.deref_mut();
|
||||||
|
|
||||||
scmd.value_of("content")
|
if let Some(new_content) = scmd.value_of("content") {
|
||||||
.map(|new_content| {
|
*e.get_content_mut() = String::from(new_content);
|
||||||
*e.get_content_mut() = String::from(new_content);
|
debug!("New content set");
|
||||||
debug!("New content set");
|
}
|
||||||
});
|
|
||||||
|
|
||||||
*e.get_header_mut() = build_toml_header(scmd, e.get_header().clone());
|
*e.get_header_mut() = build_toml_header(scmd, e.get_header().clone());
|
||||||
debug!("New header set");
|
debug!("New header set");
|
||||||
|
|
|
@ -40,10 +40,8 @@ pub fn build_toml_header(matches: &ArgMatches, mut header: Value) -> Value {
|
||||||
let (key, value) = tpl.into();
|
let (key, value) = tpl.into();
|
||||||
debug!("Splitting: {:?}", key);
|
debug!("Splitting: {:?}", key);
|
||||||
let mut split = key.split('.');
|
let mut split = key.split('.');
|
||||||
match (split.next(), &mut header) {
|
if let (Some(cur), &mut Value::Table(ref mut hdr)) = (split.next(), &mut header) {
|
||||||
(Some(cur), &mut Value::Table(ref mut hdr)) =>
|
insert_key_into(String::from(cur), &mut split, Cow::Owned(value), hdr);
|
||||||
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>) {
|
map: &mut Map<String, Value>) {
|
||||||
let next = rest_path.next();
|
let next = rest_path.next();
|
||||||
|
|
||||||
if next.is_none() {
|
if let Some(next) = next {
|
||||||
debug!("Inserting into {:?} = {:?}", current, value);
|
|
||||||
map.insert(current, parse_value(value));
|
|
||||||
} else {
|
|
||||||
debug!("Inserting into {:?} ... = {:?}", current, value);
|
debug!("Inserting into {:?} ... = {:?}", current, value);
|
||||||
match map.entry(current) {
|
match map.entry(current) {
|
||||||
Entry::Occupied(ref mut e) => {
|
Entry::Occupied(ref mut e) => {
|
||||||
match *e.get_mut() {
|
match *e.get_mut() {
|
||||||
Value::Table(ref mut t) => {
|
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!(),
|
_ => unreachable!(),
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
Entry::Vacant(v) => { v.insert(Value::Table( {
|
Entry::Vacant(v) => { v.insert(Value::Table( {
|
||||||
let mut submap = Map::new();
|
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);
|
debug!("Inserting submap = {:?}", submap);
|
||||||
submap }));
|
submap }));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
debug!("Inserting into {:?} = {:?}", current, value);
|
||||||
|
map.insert(current, parse_value(value));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue