From ef3f556099a3f13ae0c9d0719994805e4682cce7 Mon Sep 17 00:00:00 2001 From: Akshay Date: Wed, 15 Jul 2020 21:17:14 +0530 Subject: make `add` command easier to use --- src/app.rs | 3 ++- src/command.rs | 13 ++++--------- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/src/app.rs b/src/app.rs index 81a574a..dafeed5 100644 --- a/src/app.rs +++ b/src/app.rs @@ -208,7 +208,8 @@ impl App { pub fn parse_command(&mut self, input: &str) { let c = Command::from_string(input); match c { - Command::Add(name, kind, goal, auto) => { + Command::Add(name, goal, auto) => { + let kind = if goal == Some(1) { "bit" } else { "count" }; if kind == "count" { self.add_habit(Box::new(Count::new( name, diff --git a/src/command.rs b/src/command.rs index c1a855e..ae1b307 100644 --- a/src/command.rs +++ b/src/command.rs @@ -27,7 +27,7 @@ fn call_on_app(s: &mut Cursive, input: &str) { #[derive(PartialEq)] pub enum Command { - Add(String, String, Option, Option), // habit name, habit type, optional goal, auto tracked + Add(String, Option, Option), // habit name, habit type, optional goal, auto tracked MonthPrev, MonthNext, Delete(String), @@ -49,14 +49,9 @@ impl Command { if args.len() < 2 { return Command::Blank; } - let goal = args.get(2).map(|g| g.parse::().ok()).flatten(); - let auto = args.get(3).map(|g| g.parse::().ok()).flatten(); - return Command::Add( - args.get_mut(0).unwrap().to_string(), - args.get_mut(1).unwrap().to_string(), - goal, - auto, - ); + let goal = args.get(1).map(|g| g.parse::().ok()).flatten(); + let auto = args.get(2).map(|g| if g == "auto" { true } else { false }); + return Command::Add(args.get_mut(0).unwrap().to_string(), goal, auto); } "delete" | "d" => { if args.len() < 1 { -- cgit v1.2.3