Add future-check in CLI and fix for default command invokation
This commit is contained in:
parent
39a983f6fb
commit
496850a762
2 changed files with 23 additions and 4 deletions
|
@ -81,7 +81,8 @@ fn main() {
|
||||||
"create" => create(&rt),
|
"create" => create(&rt),
|
||||||
"delete" => delete(&rt),
|
"delete" => delete(&rt),
|
||||||
"list" => list(&rt),
|
"list" => list(&rt),
|
||||||
"today" => today(&rt),
|
"today" => today(&rt, false),
|
||||||
|
"status" => today(&rt, true),
|
||||||
"show" => show(&rt),
|
"show" => show(&rt),
|
||||||
"done" => done(&rt),
|
"done" => done(&rt),
|
||||||
_ => {
|
_ => {
|
||||||
|
@ -90,7 +91,7 @@ fn main() {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.unwrap_or_else(|| today(&rt));
|
.unwrap_or_else(|| today(&rt, true));
|
||||||
}
|
}
|
||||||
|
|
||||||
fn create(rt: &Runtime) {
|
fn create(rt: &Runtime) {
|
||||||
|
@ -194,7 +195,11 @@ fn delete(rt: &Runtime) {
|
||||||
|
|
||||||
// Almost the same as `list()` but with other lister functions and an additional filter for only
|
// Almost the same as `list()` but with other lister functions and an additional filter for only
|
||||||
// listing entries which are due today.
|
// listing entries which are due today.
|
||||||
fn today(rt: &Runtime) {
|
//
|
||||||
|
// if `future` is false, the `rt.cli()` will be checked or a subcommand "today" and the related
|
||||||
|
// future flag. If it is true, the check will not be performed and it is assumed that `--future`
|
||||||
|
// was passed.
|
||||||
|
fn today(rt: &Runtime, future: bool) {
|
||||||
use libimaghabit::error::ResultExt;
|
use libimaghabit::error::ResultExt;
|
||||||
use libimaghabit::error::HabitErrorKind as HEK;
|
use libimaghabit::error::HabitErrorKind as HEK;
|
||||||
|
|
||||||
|
@ -214,6 +219,13 @@ fn today(rt: &Runtime) {
|
||||||
["Name", "Basedate", "Recurr", "Comment"].iter().map(|x| String::from(*x)).collect()
|
["Name", "Basedate", "Recurr", "Comment"].iter().map(|x| String::from(*x)).collect()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let future = {
|
||||||
|
if !future {
|
||||||
|
rt.cli().subcommand_matches("today").unwrap().is_present("today-show-future")
|
||||||
|
} else {
|
||||||
|
true
|
||||||
|
}
|
||||||
|
};
|
||||||
let today = ::chrono::offset::Local::today().naive_local();
|
let today = ::chrono::offset::Local::today().naive_local();
|
||||||
|
|
||||||
let relevant : Vec<_> = { // scope, to have variable non-mutable in outer scope
|
let relevant : Vec<_> = { // scope, to have variable non-mutable in outer scope
|
||||||
|
@ -234,7 +246,7 @@ fn today(rt: &Runtime) {
|
||||||
})
|
})
|
||||||
.filter(|h| {
|
.filter(|h| {
|
||||||
let due = h.next_instance_date().map_err_trace_exit_unwrap(1);
|
let due = h.next_instance_date().map_err_trace_exit_unwrap(1);
|
||||||
due == today || due > today // today or in future
|
due == today || (future && due > today) // today or in future
|
||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
|
|
|
@ -111,6 +111,13 @@ pub fn build_ui<'a>(app: App<'a, 'a>) -> App<'a, 'a> {
|
||||||
.subcommand(SubCommand::with_name("today")
|
.subcommand(SubCommand::with_name("today")
|
||||||
.about("List habits which are due today (default command)")
|
.about("List habits which are due today (default command)")
|
||||||
.version("0.1")
|
.version("0.1")
|
||||||
|
.arg(Arg::with_name("today-show-future")
|
||||||
|
.long("future")
|
||||||
|
.short("f")
|
||||||
|
.multiple(false)
|
||||||
|
.required(false)
|
||||||
|
.takes_value(false)
|
||||||
|
.help("Also show the future"))
|
||||||
.arg(Arg::with_name("today-show-next-n")
|
.arg(Arg::with_name("today-show-next-n")
|
||||||
.long("show")
|
.long("show")
|
||||||
.short("s")
|
.short("s")
|
||||||
|
|
Loading…
Reference in a new issue