Add extensive debugging output in utilities

This commit is contained in:
Matthias Beyer 2016-01-29 20:14:27 +01:00
parent 1517d6f310
commit ef18cb1144

View file

@ -26,7 +26,15 @@ pub fn build_toml_header(matches: &ArgMatches, mut header: EntryHeader) -> Entry
debug!("Building header from cli spec"); debug!("Building header from cli spec");
if let Some(headerspecs) = matches.values_of("header") { if let Some(headerspecs) = matches.values_of("header") {
let mut main = header.toml_mut(); let mut main = header.toml_mut();
for tpl in headerspecs.into_iter().filter_map(|hs| String::from(hs).into_kv()) { debug!("headerspec = {:?}", headerspecs);
let kvs = headerspecs.into_iter()
.filter_map(|hs| {
debug!("- Processing: '{}'", hs);
let kv = String::from(hs).into_kv();
debug!("- got: '{:?}'", kv);
kv
});
for tpl in kvs {
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(".");
@ -36,6 +44,7 @@ pub fn build_toml_header(matches: &ArgMatches, mut header: EntryHeader) -> Entry
} }
} }
} }
debug!("Header = {:?}", header);
header header
} }
@ -46,8 +55,10 @@ fn insert_key_into(current: String,
let next = rest_path.next(); let next = rest_path.next();
if next.is_none() { if next.is_none() {
debug!("Inserting into {:?} = {:?}", current, value);
map.insert(current, parse_value(value)); map.insert(current, parse_value(value));
} else { } else {
debug!("Inserting into {:?} ... = {:?}", current, value);
if map.contains_key(&current) { if map.contains_key(&current) {
match map.get_mut(&current).unwrap() { match map.get_mut(&current).unwrap() {
&mut Value::Table(ref mut t) => { &mut Value::Table(ref mut t) => {
@ -58,6 +69,7 @@ fn insert_key_into(current: String,
} else { } else {
let mut submap = BTreeMap::new(); let mut submap = BTreeMap::new();
insert_key_into(String::from(next.unwrap()), rest_path, value, &mut submap); insert_key_into(String::from(next.unwrap()), rest_path, value, &mut submap);
debug!("Inserting submap = {:?}", submap);
map.insert(current, Value::Table(submap)); map.insert(current, Value::Table(submap));
} }
} }
@ -68,15 +80,18 @@ fn parse_value(value: String) -> Value {
v.chars().next() == Some('[') && v.chars().last() == Some(']') && v.len() >= 3 v.chars().next() == Some('[') && v.chars().last() == Some(']') && v.len() >= 3
} }
debug!("Building value out of: {:?}", value);
if value == "true" { if value == "true" {
debug!("Building Boolean out of: {:?}...", value);
Value::Boolean(true) Value::Boolean(true)
} else if value == "false" { } else if value == "false" {
debug!("Building Boolean out of: {:?}...", value);
Value::Boolean(false) Value::Boolean(false)
} else if is_ary(&value) { } else if is_ary(&value) {
debug!("Building Array out of: {:?}...", value);
let sub = &value[1..(value.len()-1)]; let sub = &value[1..(value.len()-1)];
Value::Array(sub.split(",").map(|v| parse_value(String::from(v))).collect()) Value::Array(sub.split(",").map(|v| parse_value(String::from(v))).collect())
} else { } else {
debug!("Building String out of: {:?}...", value);
Value::String(value) Value::String(value)
} }
} }