summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Beyer <mail@beyermatthias.de>2018-02-11 23:43:59 +0100
committerGitHub <noreply@github.com>2018-02-11 23:43:59 +0100
commitf33768abbf7f84f06b60009f00cf4dab969939e9 (patch)
tree77e5a06ea86a4625278c1aaf2358d84182c09551
parent4c95625def3ef02b2d209d497d011d11eef5917f (diff)
parentcf0f93104d1595e48148236380b537cfc20d45af (diff)
downloadimag-f33768abbf7f84f06b60009f00cf4dab969939e9.zip
imag-f33768abbf7f84f06b60009f00cf4dab969939e9.tar.gz
Merge pull request #1283 from matthiasbeyer/imag-timetrack/kairos-support-in-listing-bounds
imag-timetrack: Add kairos support in "list" subcommand
-rw-r--r--bin/domain/imag-timetrack/Cargo.toml1
-rw-r--r--bin/domain/imag-timetrack/src/list.rs48
-rw-r--r--bin/domain/imag-timetrack/src/main.rs1
-rw-r--r--doc/src/09020-changelog.md3
4 files changed, 37 insertions, 16 deletions
diff --git a/bin/domain/imag-timetrack/Cargo.toml b/bin/domain/imag-timetrack/Cargo.toml
index 2d2ce99..586472f 100644
--- a/bin/domain/imag-timetrack/Cargo.toml
+++ b/bin/domain/imag-timetrack/Cargo.toml
@@ -25,6 +25,7 @@ chrono = "0.4"
filters = "0.2"
itertools = "0.7"
prettytable-rs = "0.6"
+kairos = "0.1"
libimagstore = { version = "0.7.0", path = "../../../lib/core/libimagstore" }
libimagrt = { version = "0.7.0", path = "../../../lib/core/libimagrt" }
diff --git a/bin/domain/imag-timetrack/src/list.rs b/bin/domain/imag-timetrack/src/list.rs
index d58028a..cb0fd2a 100644
--- a/bin/domain/imag-timetrack/src/list.rs
+++ b/bin/domain/imag-timetrack/src/list.rs
@@ -17,13 +17,14 @@
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
//
-use std::str::FromStr;
-
use chrono::NaiveDateTime;
use filters::filter::Filter;
use prettytable::Table;
use prettytable::row::Row;
use prettytable::cell::Cell;
+use kairos::parser::Parsed;
+use kairos::parser::parse as kairos_parse;
+use clap::ArgMatches;
use libimagerror::trace::trace_error;
use libimagerror::trace::MapErrTrace;
@@ -39,23 +40,38 @@ pub fn list(rt: &Runtime) -> i32 {
let (_, cmd) = rt.cli().subcommand();
let cmd = cmd.unwrap(); // checked in main()
- let start = match cmd.value_of("start-time").map(::chrono::naive::NaiveDateTime::from_str) {
- None => None,
- Some(Ok(dt)) => Some(dt),
- Some(Err(e)) => {
- trace_error(&e);
- None
- }
- };
- let end = match cmd.value_of("end-time").map(::chrono::naive::NaiveDateTime::from_str) {
- None => None,
- Some(Ok(dt)) => Some(dt),
- Some(Err(e)) => {
- trace_error(&e);
- None
+ let gettime = |cmd: &ArgMatches, name| {
+ match cmd.value_of(name).map(kairos_parse) {
+ Some(Ok(Parsed::TimeType(tt))) => match tt.calculate() {
+ Ok(tt) => {
+ let dt = tt.get_moment().unwrap_or_else(|| {
+ error!("Failed to get date from '{}'", cmd.value_of(name).unwrap());
+ ::std::process::exit(1)
+ });
+
+ Some(dt.clone())
+ },
+ Err(e) => {
+ error!("Failed to calculate date from '{}': {:?}",
+ cmd.value_of(name).unwrap(), e);
+ ::std::process::exit(1)
+ },
+ },
+ Some(Ok(Parsed::Iterator(_))) => {
+ error!("Expected single point in time, got '{}', which yields a list of dates", cmd.value_of(name).unwrap());
+ ::std::process::exit(1)
+ },
+ Some(Err(e)) => {
+ trace_error(&e);
+ ::std::process::exit(1)
+ }
+ None => None,
}
};
+ let start = gettime(&cmd, "start-time");
+ let end = gettime(&cmd, "end-time");
+
let list_not_ended = cmd.is_present("list-not-ended");
list_impl(rt, start, end, list_not_ended)
diff --git a/bin/domain/imag-timetrack/src/main.rs b/bin/domain/imag-timetrack/src/main.rs
index 33f3258..c505446 100644
--- a/bin/domain/imag-timetrack/src/main.rs
+++ b/bin/domain/imag-timetrack/src/main.rs
@@ -25,6 +25,7 @@ extern crate chrono;
extern crate filters;
extern crate itertools;
extern crate prettytable;
+extern crate kairos;
extern crate libimagerror;
extern crate libimagstore;
diff --git a/doc/src/09020-changelog.md b/doc/src/09020-changelog.md
index 94fcb58..8f44f2a 100644
--- a/doc/src/09020-changelog.md
+++ b/doc/src/09020-changelog.md
@@ -19,6 +19,9 @@ Version 0.y.z and thus we can break the API like we want and need to.
This section contains the changelog from the last release to the next release.
* Major changes
+ * `imag-timetrack list --from/--to` now have `kairos` support - that means
+ that complex `--from/--to` arguments (like `yesterday` or `today-2weeks`)
+ are now possible
* Minor changes
* Bugfixes