From a5773ce86b88d0e1c1abbf03fba4aad0d965f77c Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Wed, 4 Mar 2026 00:07:08 +0200 Subject: cli: share timer elapsed-state check helper --- internal/cli/timer.go | 34 ++++++++++++++++++++-------------- 1 file changed, 20 insertions(+), 14 deletions(-) (limited to 'internal/cli/timer.go') diff --git a/internal/cli/timer.go b/internal/cli/timer.go index 22f1ce8..37e50d0 100644 --- a/internal/cli/timer.go +++ b/internal/cli/timer.go @@ -39,16 +39,12 @@ func newTimerStartCmd() *cobra.Command { Use: "start", Short: "Start the timer", RunE: func(cmd *cobra.Command, args []string) error { - rawStatus, err := timrTimer.GetRawStatus() + hasElapsed, err := timerHasElapsed() if err != nil { - return fmt.Errorf("get raw timer status: %w", err) - } - status, err := strconv.ParseFloat(rawStatus, 64) - if err != nil { - return fmt.Errorf("parse raw timer status %q: %w", rawStatus, err) + return err } - output, err := timrTimer.StartTimer(status > 0) + output, err := timrTimer.StartTimer(hasElapsed) if err != nil { return err } @@ -82,17 +78,13 @@ func newTimerContinueCmd() *cobra.Command { Use: "continue", Short: "Continue a stopped timer", RunE: func(cmd *cobra.Command, args []string) error { - rawStatus, err := timrTimer.GetRawStatus() + hasElapsed, err := timerHasElapsed() if err != nil { - return fmt.Errorf("get raw timer status: %w", err) - } - status, err := strconv.ParseFloat(rawStatus, 64) - if err != nil { - return fmt.Errorf("parse raw timer status %q: %w", rawStatus, err) + return err } output := "Timer is at 0, cannot continue." - if status > 0 { + if hasElapsed { output, err = timrTimer.StartTimer(true) if err != nil { return err @@ -248,3 +240,17 @@ func syncWorktimeWithTimer(cmd *cobra.Command, start bool) error { return err } + +func timerHasElapsed() (bool, error) { + rawStatus, err := timrTimer.GetRawStatus() + if err != nil { + return false, fmt.Errorf("get raw timer status: %w", err) + } + + status, err := strconv.ParseFloat(rawStatus, 64) + if err != nil { + return false, fmt.Errorf("parse raw timer status %q: %w", rawStatus, err) + } + + return status > 0, nil +} -- cgit v1.2.3