Merge pull request #1283 from matthiasbeyer/imag-timetrack/kairos-support-in-listing-bounds
imag-timetrack: Add kairos support in "list" subcommand
This commit is contained in:
commit
f33768abbf
4 changed files with 37 additions and 16 deletions
|
@ -25,6 +25,7 @@ chrono = "0.4"
|
||||||
filters = "0.2"
|
filters = "0.2"
|
||||||
itertools = "0.7"
|
itertools = "0.7"
|
||||||
prettytable-rs = "0.6"
|
prettytable-rs = "0.6"
|
||||||
|
kairos = "0.1"
|
||||||
|
|
||||||
libimagstore = { version = "0.7.0", path = "../../../lib/core/libimagstore" }
|
libimagstore = { version = "0.7.0", path = "../../../lib/core/libimagstore" }
|
||||||
libimagrt = { version = "0.7.0", path = "../../../lib/core/libimagrt" }
|
libimagrt = { version = "0.7.0", path = "../../../lib/core/libimagrt" }
|
||||||
|
|
|
@ -17,13 +17,14 @@
|
||||||
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
//
|
//
|
||||||
|
|
||||||
use std::str::FromStr;
|
|
||||||
|
|
||||||
use chrono::NaiveDateTime;
|
use chrono::NaiveDateTime;
|
||||||
use filters::filter::Filter;
|
use filters::filter::Filter;
|
||||||
use prettytable::Table;
|
use prettytable::Table;
|
||||||
use prettytable::row::Row;
|
use prettytable::row::Row;
|
||||||
use prettytable::cell::Cell;
|
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::trace_error;
|
||||||
use libimagerror::trace::MapErrTrace;
|
use libimagerror::trace::MapErrTrace;
|
||||||
|
@ -39,23 +40,38 @@ pub fn list(rt: &Runtime) -> i32 {
|
||||||
let (_, cmd) = rt.cli().subcommand();
|
let (_, cmd) = rt.cli().subcommand();
|
||||||
let cmd = cmd.unwrap(); // checked in main()
|
let cmd = cmd.unwrap(); // checked in main()
|
||||||
|
|
||||||
let start = match cmd.value_of("start-time").map(::chrono::naive::NaiveDateTime::from_str) {
|
let gettime = |cmd: &ArgMatches, name| {
|
||||||
None => None,
|
match cmd.value_of(name).map(kairos_parse) {
|
||||||
Some(Ok(dt)) => Some(dt),
|
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)) => {
|
Some(Err(e)) => {
|
||||||
trace_error(&e);
|
trace_error(&e);
|
||||||
None
|
::std::process::exit(1)
|
||||||
}
|
}
|
||||||
};
|
|
||||||
let end = match cmd.value_of("end-time").map(::chrono::naive::NaiveDateTime::from_str) {
|
|
||||||
None => None,
|
None => None,
|
||||||
Some(Ok(dt)) => Some(dt),
|
|
||||||
Some(Err(e)) => {
|
|
||||||
trace_error(&e);
|
|
||||||
None
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let start = gettime(&cmd, "start-time");
|
||||||
|
let end = gettime(&cmd, "end-time");
|
||||||
|
|
||||||
let list_not_ended = cmd.is_present("list-not-ended");
|
let list_not_ended = cmd.is_present("list-not-ended");
|
||||||
|
|
||||||
list_impl(rt, start, end, list_not_ended)
|
list_impl(rt, start, end, list_not_ended)
|
||||||
|
|
|
@ -25,6 +25,7 @@ extern crate chrono;
|
||||||
extern crate filters;
|
extern crate filters;
|
||||||
extern crate itertools;
|
extern crate itertools;
|
||||||
extern crate prettytable;
|
extern crate prettytable;
|
||||||
|
extern crate kairos;
|
||||||
|
|
||||||
extern crate libimagerror;
|
extern crate libimagerror;
|
||||||
extern crate libimagstore;
|
extern crate libimagstore;
|
||||||
|
|
|
@ -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.
|
This section contains the changelog from the last release to the next release.
|
||||||
|
|
||||||
* Major changes
|
* 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
|
* Minor changes
|
||||||
* Bugfixes
|
* Bugfixes
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue