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/command.rs | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) (limited to 'src/command.rs') 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