diff options
-rw-r--r-- | src/app/impl_self.rs | 21 | ||||
-rw-r--r-- | src/main.rs | 14 |
2 files changed, 34 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) { |
diff --git a/src/main.rs b/src/main.rs index d96119e..050a296 100644 --- a/src/main.rs +++ b/src/main.rs | |||
@@ -33,6 +33,14 @@ fn main() { | |||
33 | .value_name("CMD") | 33 | .value_name("CMD") |
34 | .help("run a dijo command"), | 34 | .help("run a dijo command"), |
35 | ) | 35 | ) |
36 | .arg( | ||
37 | Arg::with_name("list") | ||
38 | .short("l") | ||
39 | .long("list") | ||
40 | .takes_value(false) | ||
41 | .help("list dijo habits") | ||
42 | .conflicts_with("command"), | ||
43 | ) | ||
36 | .get_matches(); | 44 | .get_matches(); |
37 | if let Some(c) = matches.value_of("command") { | 45 | if let Some(c) = matches.value_of("command") { |
38 | let command = Command::from_string(c); | 46 | let command = Command::from_string(c); |
@@ -49,6 +57,12 @@ fn main() { | |||
49 | "Commands other than `track-up` and `track-down` are currently not supported!" | 57 | "Commands other than `track-up` and `track-down` are currently not supported!" |
50 | ), | 58 | ), |
51 | } | 59 | } |
60 | } else if matches.is_present("list") { | ||
61 | let app = App::load_state(); | ||
62 | let _habit_names = app.list_habit(); | ||
63 | for h in _habit_names { | ||
64 | println!("{}", h); | ||
65 | } | ||
52 | } else { | 66 | } else { |
53 | let mut s = termion().unwrap(); | 67 | let mut s = termion().unwrap(); |
54 | let app = App::load_state(); | 68 | let app = App::load_state(); |