Do not print table if table is empty anyways

When listing timetrackings, we do not want to print an empty table if
there aren't any timetrackings.

Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
This commit is contained in:
Matthias Beyer 2019-02-06 01:35:01 +01:00
parent 81912ac5cd
commit fe9409a5dc

View file

@ -121,7 +121,9 @@ pub fn list_impl(rt: &Runtime,
let mut table = Table::new(); let mut table = Table::new();
table.set_titles(Row::new(["Tag", "Start", "End"].into_iter().map(|s| Cell::new(s)).collect())); table.set_titles(Row::new(["Tag", "Start", "End"].into_iter().map(|s| Cell::new(s)).collect()));
rt.store() let mut table_empty = true;
let table = rt.store()
.get_timetrackings() .get_timetrackings()
.map_err_trace_exit_unwrap() .map_err_trace_exit_unwrap()
.trace_unwrap() .trace_unwrap()
@ -165,15 +167,21 @@ pub fn list_impl(rt: &Runtime,
let _ = rt.report_touched(e.get_location()).unwrap_or_exit(); let _ = rt.report_touched(e.get_location()).unwrap_or_exit();
table_empty = false;
Ok(tab) Ok(tab)
}) })
}) })
.map_err_trace_exit_unwrap() .map_err_trace_exit_unwrap();
.print(&mut rt.stdout())
if !table_empty {
table.print(&mut rt.stdout())
.context(err_msg("Failed to print table")) .context(err_msg("Failed to print table"))
.map_err(Error::from) .map_err(Error::from)
.map(|_| 0) .map(|_| 0)
.map_err_trace() .map_err_trace()
.unwrap_or(1) .unwrap_or(1)
} else {
0
}
} }