summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Beyer <mail@beyermatthias.de>2018-01-16 16:26:25 +0100
committerGitHub <noreply@github.com>2018-01-16 16:26:25 +0100
commitd5569cea63e46f7ba1ab2ee6c8d482db34784ee1 (patch)
tree632d71b1e88cfea28b9c09a97b77ba33f978e672
parent2b0dfec4578f43330414523f0c86dd2f827b1002 (diff)
parent45ac9b41329b3e64a8df29a7acfae97fe330f334 (diff)
downloadimag-d5569cea63e46f7ba1ab2ee6c8d482db34784ee1.zip
imag-d5569cea63e46f7ba1ab2ee6c8d482db34784ee1.tar.gz
Merge pull request #1217 from matthiasbeyer/imag-timetrack/table-list
Change list command to use a table for output
-rw-r--r--bin/domain/imag-timetrack/Cargo.toml1
-rw-r--r--bin/domain/imag-timetrack/src/list.rs49
-rw-r--r--bin/domain/imag-timetrack/src/main.rs3
-rw-r--r--doc/src/09020-changelog.md1
4 files changed, 42 insertions, 12 deletions
diff --git a/bin/domain/imag-timetrack/Cargo.toml b/bin/domain/imag-timetrack/Cargo.toml
index 462d16a..84bf4fa 100644
--- a/bin/domain/imag-timetrack/Cargo.toml
+++ b/bin/domain/imag-timetrack/Cargo.toml
@@ -25,6 +25,7 @@ log = "0.3"
chrono = "0.4"
filters = "0.2"
itertools = "0.7"
+prettytable-rs = "0.6"
libimagstore = { version = "0.6.0", path = "../../../lib/core/libimagstore" }
libimagrt = { version = "0.6.0", path = "../../../lib/core/libimagrt" }
diff --git a/bin/domain/imag-timetrack/src/list.rs b/bin/domain/imag-timetrack/src/list.rs
index 88c6150..2b02509 100644
--- a/bin/domain/imag-timetrack/src/list.rs
+++ b/bin/domain/imag-timetrack/src/list.rs
@@ -21,6 +21,9 @@ use std::str::FromStr;
use chrono::NaiveDateTime;
use filters::filter::Filter;
+use prettytable::Table;
+use prettytable::row::Row;
+use prettytable::cell::Cell;
use libimagerror::trace::trace_error;
use libimagerror::trace::MapErrTrace;
@@ -28,6 +31,7 @@ use libimagerror::iter::TraceIterator;
use libimagstore::store::FileLockEntry;
use libimagtimetrack::timetrackingstore::TimeTrackStore;
use libimagtimetrack::timetracking::TimeTracking;
+use libimagtimetrack::error::Result;
use libimagrt::runtime::Runtime;
@@ -93,13 +97,18 @@ pub fn list_impl(rt: &Runtime,
let filter = start_time_filter.and(end_time_filter);
+ let mut table = Table::new();
+ table.set_titles(Row::new(["Tag", "Start", "End"].into_iter().map(|s| Cell::new(s)).collect()));
+
+ let mut stdout = ::std::io::stdout();
+
rt.store()
.get_timetrackings()
.and_then(|iter| {
iter.trace_unwrap()
.filter(|e| filter.filter(e))
- .fold(Ok(()), |acc, e| {
- acc.and_then(|_| {
+ .fold(Ok(table), |acc: Result<_>, e| {
+ acc.and_then(|mut tab: Table| {
debug!("Processing {:?}", e.get_location());
let tag = e.get_timetrack_tag()?;
@@ -111,15 +120,35 @@ pub fn list_impl(rt: &Runtime,
let end = e.get_end_datetime()?;
debug!(" -> end = {:?}", end);
- match (start, end) {
- (None, _) => println!("{} has no start time.", tag),
- (Some(s), None) => println!("{} | {} - ...", tag, s),
- (Some(s), Some(e)) => println!("{} | {} - {}", tag, s, e),
- }
-
- Ok(())
+ let v = match (start, end) {
+ (None, _) => vec![String::from(tag.as_str()), String::from(""), String::from("")],
+ (Some(s), None) => {
+ vec![
+ String::from(tag.as_str()),
+ format!("{}", s),
+ String::from(""),
+ ]
+ },
+ (Some(s), Some(e)) => {
+ vec![
+ String::from(tag.as_str()),
+ format!("{}", s),
+ format!("{}", e),
+ ]
+ },
+ };
+
+ let cells : Vec<Cell> = v
+ .into_iter()
+ .map(|s| Cell::new(&s))
+ .collect();
+ tab.add_row(Row::new(cells));
+
+ Ok(tab)
})
- })
+ })?
+ .print(&mut stdout)
+ .map_err(|_| String::from("Failed printing table").into())
})
.map(|_| 0)
.map_err_trace()
diff --git a/bin/domain/imag-timetrack/src/main.rs b/bin/domain/imag-timetrack/src/main.rs
index 55a8d01..6d736cb 100644
--- a/bin/domain/imag-timetrack/src/main.rs
+++ b/bin/domain/imag-timetrack/src/main.rs
@@ -20,12 +20,11 @@
#[macro_use]
extern crate log;
-#[macro_use]
-
extern crate clap;
extern crate chrono;
extern crate filters;
extern crate itertools;
+extern crate prettytable;
extern crate libimagerror;
extern crate libimagstore;
diff --git a/doc/src/09020-changelog.md b/doc/src/09020-changelog.md
index f9e37d0..bbce7b8 100644
--- a/doc/src/09020-changelog.md
+++ b/doc/src/09020-changelog.md
@@ -37,6 +37,7 @@ This section contains the changelog from the last release to the next release.
chaining
* `libimagbookmark` does not longer wrap types from the store.
* The `toml-query` dependency was updated to 0.5.0
+ * `imag-timetrack list` lists with a table now
* Bugfixes
## 0.5.0