From 9dfe454cd8bc816522446e7e3b9f45630c886112 Mon Sep 17 00:00:00 2001 From: Guillaume Hormiere Date: Wed, 22 Jul 2020 00:38:01 +0200 Subject: 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 --- src/main.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'src/main.rs') 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() { .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,12 @@ fn main() { "Commands other than `track-up` and `track-down` are currently not supported!" ), } + } else if matches.is_present("list") { + let app = App::load_state(); + let _habit_names = app.list_habit(); + for h in _habit_names { + println!("{}", h); + } } else { let mut s = termion().unwrap(); let app = App::load_state(); -- cgit v1.2.3