From acc6d135e5242e5e30e2993db88e74ad99299585 Mon Sep 17 00:00:00 2001 From: Brian Buller Date: Thu, 12 Apr 2018 16:11:54 -0500 Subject: [PATCH] Actually fix `switch` --- helpers.go | 6 +++--- timer_operations.go | 21 ++++++++------------- 2 files changed, 11 insertions(+), 16 deletions(-) diff --git a/helpers.go b/helpers.go index 05801ec..be25462 100644 --- a/helpers.go +++ b/helpers.go @@ -74,11 +74,11 @@ func InferTimerDetailString(t *gime.TimeEntry) string { } func TimerDetailToString(t *gime.TimeEntry) string { - ret := t.GetStart().Format("15:04") + ret := t.GetStart().Format("15:04") + " - " if t.GetEnd().IsZero() { - ret += " (" + padLeft(sinceToString(t.GetStart()), len("00h 00m 00s")) + ") " + ret += "**:** (" + padLeft(sinceToString(t.GetStart()), len("00h 00m 00s")) + ") " } else { - ret += " (" + padLeft(diffToString(t.GetStart(), t.GetEnd()), len("00h 00m 00s")) + ") " + ret += t.GetEnd().Format("15:04") + " (" + padLeft(diffToString(t.GetStart(), t.GetEnd()), len("00h 00m 00s")) + ") " } if t.GetTags().Length() > 0 { ret += " [ " diff --git a/timer_operations.go b/timer_operations.go index 8aed424..e730796 100644 --- a/timer_operations.go +++ b/timer_operations.go @@ -38,7 +38,7 @@ func cmdStartTimer(args []string) int { return 1 } - fmt.Println(" " + TimerToString(entry)) + fmt.Println("Started:", TimerToString(entry)) return 0 } @@ -61,27 +61,22 @@ func cmdContinueTimer(args []string) int { // switchTimer performs a stop on any currently running timers // and starts a new timer with the given arguments func cmdSwitchTimer(args []string) int { - var foundId bool + stopId := "@all" + stopIdIdx := -1 for i := range args { // see if we have a timer id in the args if args[i][0] == '@' { - foundId = true + stopId = args[i] + stopIdIdx = i } } - stopArgs := make([]string, len(args)) - copy(stopArgs, args) - if !foundId { - // We didn't find one, so make sure we stop _all_ timers - stopArgs = append(stopArgs, "@all") + if stopIdIdx >= 0 { + args = append(args[:stopIdIdx], args[stopIdIdx+1:]...) } - fmt.Println(stopArgs) - fmt.Println(args) - return 0 - if cmdStopTimer(args) != 0 { + if cmdStopTimer([]string{stopId}) != 0 { // Error while stopping timers return 1 } - fmt.Println("Started Timer:") return cmdStartTimer(args) }