diff options
author | Guillaume Hormiere <[email protected]> | 2020-07-21 23:38:01 +0100 |
---|---|---|
committer | Guillaume Hormiere <[email protected]> | 2020-07-21 23:38:01 +0100 |
commit | 9dfe454cd8bc816522446e7e3b9f45630c886112 (patch) | |
tree | 4b31fbdd318ba58f55b2723fca55dbc4ca10e6a5 /src/app/impl_self.rs | |
parent | 9102dc72be19f87ec9e2893a35f5020957135c1c (diff) |
Add list command for shell script purpose
Usage dijo -l for printing the habit names list
Add check on habit add to avoid duplicate habits
Diffstat (limited to 'src/app/impl_self.rs')
-rw-r--r-- | src/app/impl_self.rs | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/src/app/impl_self.rs b/src/app/impl_self.rs index 95f1871..38162ee 100644 --- a/src/app/impl_self.rs +++ b/src/app/impl_self.rs | |||
@@ -33,8 +33,27 @@ impl App { | |||
33 | }; | 33 | }; |
34 | } | 34 | } |
35 | 35 | ||
36 | pub fn list_habit(&self) -> Vec<String> { | ||
37 | let mut habits_names: Vec<String> = vec![]; | ||
38 | for h in self.habits.iter() { | ||
39 | habits_names.push(h.name()) | ||
40 | } | ||
41 | return habits_names; | ||
42 | } | ||
43 | |||
36 | pub fn add_habit(&mut self, h: Box<dyn HabitWrapper>) { | 44 | pub fn add_habit(&mut self, h: Box<dyn HabitWrapper>) { |
37 | self.habits.push(h); | 45 | if self |
46 | .habits | ||
47 | .iter() | ||
48 | .filter(|hab| hab.name() == h.name()) | ||
49 | .count() | ||
50 | > 0 | ||
51 | { | ||
52 | self.message | ||
53 | .set_message(format!("Habit `{}` allready exist", h.name())) | ||
54 | } else { | ||
55 | self.habits.push(h); | ||
56 | } | ||
38 | } | 57 | } |
39 | 58 | ||
40 | pub fn delete_by_name(&mut self, name: &str) { | 59 | pub fn delete_by_name(&mut self, name: &str) { |