diff options
author | Akshay <nerdy@peppe.rs> | 2020-07-23 13:20:10 +0530 |
---|---|---|
committer | Akshay <nerdy@peppe.rs> | 2020-07-23 13:20:10 +0530 |
commit | b763206c9fc24f54af4bfebe80d2a7b7579557d5 (patch) | |
tree | 7b4bc347fc37601b1454562d74c5346bb3da4864 | |
parent | 59b40932d4602fc7bf84f123930f9a0eb187f4a1 (diff) | |
parent | b0b6c04a052955834f0603df79db7a0a517a9b9d (diff) |
Merge branch 'fix/duplicate-habits'
-rw-r--r-- | src/app/impl_self.rs | 6 | ||||
-rw-r--r-- | src/main.rs | 12 |
2 files changed, 18 insertions, 0 deletions
diff --git a/src/app/impl_self.rs b/src/app/impl_self.rs index 1ed19e6..a806dc5 100644 --- a/src/app/impl_self.rs +++ b/src/app/impl_self.rs @@ -217,6 +217,12 @@ impl App { match result { Ok(c) => match c { Command::Add(name, goal, auto) => { + if let Some(_) = self.habits.iter().find(|x| x.name() == name) { + self.message.set_kind(MessageKind::Error); + self.message + .set_message(format!("Habit `{}` already exist", &name)); + return; + } let kind = if goal == Some(1) { "bit" } else { "count" }; if kind == "count" { self.add_habit(Box::new(Count::new(name, goal.unwrap_or(0), auto))); diff --git a/src/main.rs b/src/main.rs index d96119e..5523073 100644 --- a/src/main.rs +++ b/src/main.rs @@ -33,6 +33,14 @@ fn main() { .value_name("CMD") .help("run a dijo command"), ) + .arg( + Arg::with_name("list") + .short("l") + .long("list") + .takes_value(false) + .help("list dijo habits") + .conflicts_with("command"), + ) .get_matches(); if let Some(c) = matches.value_of("command") { let command = Command::from_string(c); @@ -49,6 +57,10 @@ fn main() { "Commands other than `track-up` and `track-down` are currently not supported!" ), } + } else if matches.is_present("list") { + for h in App::load_state().list_habits() { + println!("{}", h); + } } else { let mut s = termion().unwrap(); let app = App::load_state(); |