aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/app/impl_self.rs6
-rw-r--r--src/main.rs12
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 {
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)));
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() {
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,10 @@ 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 for h in App::load_state().list_habits() {
62 println!("{}", h);
63 }
52 } else { 64 } else {
53 let mut s = termion().unwrap(); 65 let mut s = termion().unwrap();
54 let app = App::load_state(); 66 let app = App::load_state();