aboutsummaryrefslogtreecommitdiff
path: root/src/app/impl_self.rs
diff options
context:
space:
mode:
authorAkshay <[email protected]>2020-07-23 08:50:10 +0100
committerAkshay <[email protected]>2020-07-23 08:50:10 +0100
commitb763206c9fc24f54af4bfebe80d2a7b7579557d5 (patch)
tree7b4bc347fc37601b1454562d74c5346bb3da4864 /src/app/impl_self.rs
parent59b40932d4602fc7bf84f123930f9a0eb187f4a1 (diff)
parentb0b6c04a052955834f0603df79db7a0a517a9b9d (diff)
Merge branch 'fix/duplicate-habits'
Diffstat (limited to 'src/app/impl_self.rs')
-rw-r--r--src/app/impl_self.rs6
1 files changed, 6 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 {
217 match result { 217 match result {
218 Ok(c) => match c { 218 Ok(c) => match c {
219 Command::Add(name, goal, auto) => { 219 Command::Add(name, goal, auto) => {
220 if let Some(_) = self.habits.iter().find(|x| x.name() == name) {
221 self.message.set_kind(MessageKind::Error);
222 self.message
223 .set_message(format!("Habit `{}` already exist", &name));
224 return;
225 }
220 let kind = if goal == Some(1) { "bit" } else { "count" }; 226 let kind = if goal == Some(1) { "bit" } else { "count" };
221 if kind == "count" { 227 if kind == "count" {
222 self.add_habit(Box::new(Count::new(name, goal.unwrap_or(0), auto))); 228 self.add_habit(Box::new(Count::new(name, goal.unwrap_or(0), auto)));