From 5174472bf0cdb29cdc02f37890fd9e67b744a8d7 Mon Sep 17 00:00:00 2001 From: Brian Buller Date: Wed, 6 Mar 2019 08:09:38 -0600 Subject: [PATCH] Prepend new timers to front of list, not back Also, add Remove operation --- app_state.go | 7 +++++++ timer_ops.go | 27 +++++++++++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/app_state.go b/app_state.go index cae742d..a4405f9 100644 --- a/app_state.go +++ b/app_state.go @@ -150,6 +150,13 @@ func (a *AppState) initialize() { }, a.opSwitchTimer, ) + a.addOperation("rm", + []string{ + "rm [id] - Removes the timer with the given id", + " WARNING: CANNOT BE UNDONE", + }, + a.opRemoveTimer, + ) a.addOperation("archive", []string{ "archive [id] - Archive the timer with the given id", diff --git a/timer_ops.go b/timer_ops.go index 3bbf869..87028d3 100644 --- a/timer_ops.go +++ b/timer_ops.go @@ -267,6 +267,33 @@ func (a *AppState) opArchiveTimer(args []string) int { return 0 } +func (a *AppState) opRemoveTimer(args []string) int { + if len(args) == 0 { + fmt.Println("No timer id given") + return 1 + } + id, err := strconv.Atoi(args[0]) + if err != nil { + fmt.Println("Invalid timer id given: " + args[0]) + } + t, err := a.TimerList.GetTimer(id) + if err != nil { + fmt.Println("Error getting timer with id: " + args[0]) + return 1 + } + if err = a.TimerList.RemoveTimerById(id); err != nil { + fmt.Println("Error Removing Timer: " + err.Error()) + return 1 + } + fmt.Println("Timer removed") + fmt.Println(TimerToString(t)) + if err := a.WriteList(); err != nil { + fmt.Println(err.Error()) + return 1 + } + return 0 +} + func (a *AppState) opModifyTimer(args []string) int { var timer *timertxt.Timer var contexts, projects []string