summaryrefslogtreecommitdiffstats
path: root/bin/domain/imag-timetrack/src/list.rs
diff options
context:
space:
mode:
authorMatthias Beyer <mail@beyermatthias.de>2019-02-06 01:35:01 +0100
committerMatthias Beyer <mail@beyermatthias.de>2019-02-11 03:52:04 +0100
commitfe9409a5dc2dab4adb19076decf3d7c94389726f (patch)
tree812d9b5dc27be5749a548be5aa78baf86242e7db /bin/domain/imag-timetrack/src/list.rs
parent81912ac5cd45b3728cf1bcd49a39a53ee468709c (diff)
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>
Diffstat (limited to 'bin/domain/imag-timetrack/src/list.rs')
-rw-r--r--bin/domain/imag-timetrack/src/list.rs24
1 files changed, 16 insertions, 8 deletions
diff --git a/bin/domain/imag-timetrack/src/list.rs b/bin/domain/imag-timetrack/src/list.rs
index 738f1bbd..8df8f7e5 100644
--- a/bin/domain/imag-timetrack/src/list.rs
+++ b/bin/domain/imag-timetrack/src/list.rs
@@ -121,7 +121,9 @@ pub fn list_impl(rt: &Runtime,
let mut table = Table::new();
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()
.map_err_trace_exit_unwrap()
.trace_unwrap()
@@ -165,15 +167,21 @@ pub fn list_impl(rt: &Runtime,
let _ = rt.report_touched(e.get_location()).unwrap_or_exit();
+ table_empty = false;
Ok(tab)
})
})
- .map_err_trace_exit_unwrap()
- .print(&mut rt.stdout())
- .context(err_msg("Failed to print table"))
- .map_err(Error::from)
- .map(|_| 0)
- .map_err_trace()
- .unwrap_or(1)
+ .map_err_trace_exit_unwrap();
+
+ if !table_empty {
+ table.print(&mut rt.stdout())
+ .context(err_msg("Failed to print table"))
+ .map_err(Error::from)
+ .map(|_| 0)
+ .map_err_trace()
+ .unwrap_or(1)
+ } else {
+ 0
+ }
}