Prepend new timers to front of list, not back

Also, add Remove operation
This commit is contained in:
Brian Buller 2019-03-06 08:09:38 -06:00
parent 6b1cc0866f
commit 5174472bf0
2 changed files with 34 additions and 0 deletions

View File

@ -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",

View File

@ -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