src/api/cli/text_table.rs - format_object: skip optional properties without data

This commit is contained in:
Dietmar Maurer 2020-04-27 06:23:26 +02:00
parent e229c3d582
commit 9e10d85538

View File

@ -597,7 +597,7 @@ fn format_object<W: Write>(
let mut all_right_aligned = true; let mut all_right_aligned = true;
for name in properties_to_print.iter() { for name in properties_to_print.iter() {
let (_optional, prop_schema) = match schema.lookup(name) { let (optional, prop_schema) = match schema.lookup(name) {
Some(tup) => tup, Some(tup) => tup,
None => bail!("property {} does not exist in schema.", name), None => bail!("property {} does not exist in schema.", name),
}; };
@ -615,6 +615,12 @@ fn format_object<W: Write>(
if !right_align { all_right_aligned = false; } if !right_align { all_right_aligned = false; }
if optional {
if let Some(object) = data.as_object() {
if object.get(name).is_none() { continue; }
}
}
let header_width = header.chars().count(); let header_width = header.chars().count();
if header_width > max_name_width { max_name_width = header_width; } if header_width > max_name_width { max_name_width = header_width; }