summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Beyer <mail@beyermatthias.de>2018-03-22 21:15:20 +0100
committerGitHub <noreply@github.com>2018-03-22 21:15:20 +0100
commit58f50ac2f908635d8738026ac2777d185470fb4e (patch)
treebd5a9960892162a35ffc50a02fbd08d1dc3dcb8b
parentcc9c746cb423ed082be1552f4384a7556640c5ee (diff)
parent00d485c3d35c3a34f5d1bfd0985d9e2c06b63ed4 (diff)
downloadimag-58f50ac2f908635d8738026ac2777d185470fb4e.zip
imag-58f50ac2f908635d8738026ac2777d185470fb4e.tar.gz
Merge pull request #1358 from matthiasbeyer/imag-habit/show-done
imag-habit: show done
-rw-r--r--bin/domain/imag-habit/src/main.rs45
-rw-r--r--bin/domain/imag-habit/src/ui.rs14
2 files changed, 50 insertions, 9 deletions
diff --git a/bin/domain/imag-habit/src/main.rs b/bin/domain/imag-habit/src/main.rs
index 0a7288b..4e62592 100644
--- a/bin/domain/imag-habit/src/main.rs
+++ b/bin/domain/imag-habit/src/main.rs
@@ -229,11 +229,14 @@ fn today(rt: &Runtime, future: bool) {
use libimaghabit::error::ResultExt;
use libimaghabit::error::HabitErrorKind as HEK;
- let future = {
+ let (future, show_done) = {
if !future {
- rt.cli().subcommand_matches("today").unwrap().is_present("today-show-future")
+ let scmd = rt.cli().subcommand_matches("today").unwrap();
+ let futu = scmd.is_present("today-show-future");
+ let done = scmd.is_present("today-done");
+ (futu, done)
} else {
- true
+ (true, rt.cli().subcommand_matches("status").unwrap().is_present("status-done"))
}
};
let today = ::chrono::offset::Local::today().naive_local();
@@ -257,6 +260,8 @@ fn today(rt: &Runtime, future: bool) {
.filter(|h| {
let due = h.next_instance_date().map_err_trace_exit_unwrap(1);
// today or in future
+ debug!("Checking {due:?} == {today:?} or (future = {fut} && {due:?} > {today:?}",
+ due = due, today = today, fut = future);
due.map(|d| d == today || (future && d > today)).unwrap_or(false)
})
.collect();
@@ -266,15 +271,17 @@ fn today(rt: &Runtime, future: bool) {
relevant
};
- let any_today_relevant = relevant
+ let any_today_relevant = show_done || relevant
.iter()
.filter(|h| {
let due = h.next_instance_date().map_err_trace_exit_unwrap(1);
+ debug!("Checking: {:?} == {:?}", due, today);
due.map(|d| d == today).unwrap_or(false) // relevant today
})
- .count() == 0;
+ .count() != 0;
- if any_today_relevant {
+ debug!("Any today relevant = {}", any_today_relevant);
+ if !any_today_relevant {
let n = rt
.cli()
.subcommand_matches("today")
@@ -294,8 +301,14 @@ fn today(rt: &Runtime, future: bool) {
let date = element.next_instance_date().map_err_trace_exit_unwrap(1);
let name = element.habit_name().map_err_trace_exit_unwrap(1);
- if let Some(date) = date { // if there is a date
- info!(" * {date}: {name}", date = date, name = name);
+ if let Some(date) = date {
+ let is_done = element
+ .instance_exists_for_date(&date)
+ .map_err_trace_exit_unwrap(1);
+
+ if show_done || !is_done {
+ info!(" * {date}: {name}", date = date, name = name);
+ }
}
}
} else {
@@ -323,7 +336,21 @@ fn today(rt: &Runtime, future: bool) {
table.set_titles(Row::new(header));
let mut empty = true;
- for (i, e) in relevant.into_iter().enumerate() {
+ for (i, e) in relevant.into_iter()
+ .filter(|habit| {
+ show_done || {
+ habit
+ .next_instance_date()
+ .map_err_trace_exit_unwrap(1)
+ .map(|date| {
+ habit.instance_exists_for_date(&date)
+ .map_err_trace_exit_unwrap(1)
+ })
+ .unwrap_or(false)
+ }
+ })
+ .enumerate()
+ {
let mut v = vec![format!("{}", i)];
let mut list = lister_fn(&e);
v.append(&mut list);
diff --git a/bin/domain/imag-habit/src/ui.rs b/bin/domain/imag-habit/src/ui.rs
index eee798b..9f501f2 100644
--- a/bin/domain/imag-habit/src/ui.rs
+++ b/bin/domain/imag-habit/src/ui.rs
@@ -24,6 +24,13 @@ pub fn build_ui<'a>(app: App<'a, 'a>) -> App<'a, 'a> {
.subcommand(SubCommand::with_name("status")
.about("Show the current status. Remind of not-yet-done habits, shows upcoming. Default if no command is passed. Also alias for 'today --future'")
.version("0.1")
+ .arg(Arg::with_name("status-done")
+ .long("done")
+ .short("D")
+ .multiple(false)
+ .required(false)
+ .takes_value(false)
+ .help("Show entries which are done."))
)
.subcommand(SubCommand::with_name("create")
@@ -139,6 +146,13 @@ pub fn build_ui<'a>(app: App<'a, 'a>) -> App<'a, 'a> {
.takes_value(true)
.value_name("N")
.help("Show the N next relevant entries. Default = 5"))
+ .arg(Arg::with_name("today-done")
+ .long("done")
+ .short("D")
+ .multiple(false)
+ .required(false)
+ .takes_value(false)
+ .help("Show entries which are done."))
)
.subcommand(SubCommand::with_name("done")