aboutsummaryrefslogtreecommitdiff
path: root/src/command.rs
diff options
context:
space:
mode:
authorAkshay <[email protected]>2020-07-15 16:47:14 +0100
committerAkshay <[email protected]>2020-07-15 16:47:14 +0100
commitef3f556099a3f13ae0c9d0719994805e4682cce7 (patch)
treea93a91107d2744cce109b2c041281d5dcf6d045f /src/command.rs
parent859ac5d3e49bc9a123df3f5a74b43d2281a3bed1 (diff)
make `add` command easier to use
Diffstat (limited to 'src/command.rs')
-rw-r--r--src/command.rs13
1 files changed, 4 insertions, 9 deletions
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) {
27 27
28#[derive(PartialEq)] 28#[derive(PartialEq)]
29pub enum Command { 29pub enum Command {
30 Add(String, String, Option<u32>, Option<bool>), // habit name, habit type, optional goal, auto tracked 30 Add(String, Option<u32>, Option<bool>), // habit name, habit type, optional goal, auto tracked
31 MonthPrev, 31 MonthPrev,
32 MonthNext, 32 MonthNext,
33 Delete(String), 33 Delete(String),
@@ -49,14 +49,9 @@ impl Command {
49 if args.len() < 2 { 49 if args.len() < 2 {
50 return Command::Blank; 50 return Command::Blank;
51 } 51 }
52 let goal = args.get(2).map(|g| g.parse::<u32>().ok()).flatten(); 52 let goal = args.get(1).map(|g| g.parse::<u32>().ok()).flatten();
53 let auto = args.get(3).map(|g| g.parse::<bool>().ok()).flatten(); 53 let auto = args.get(2).map(|g| if g == "auto" { true } else { false });
54 return Command::Add( 54 return Command::Add(args.get_mut(0).unwrap().to_string(), goal, auto);
55 args.get_mut(0).unwrap().to_string(),
56 args.get_mut(1).unwrap().to_string(),
57 goal,
58 auto,
59 );
60 } 55 }
61 "delete" | "d" => { 56 "delete" | "d" => {
62 if args.len() < 1 { 57 if args.len() < 1 {