summaryrefslogtreecommitdiff
path: root/internal/cli/timer.go
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2026-03-04 00:07:08 +0200
committerPaul Buetow <paul@buetow.org>2026-03-04 00:07:08 +0200
commita5773ce86b88d0e1c1abbf03fba4aad0d965f77c (patch)
tree5cf85b95b15adaf640d7a1d1a9b1ec1c28fb5753 /internal/cli/timer.go
parentc6a9ee27141fd1a57813fcc7f54fe370408bae14 (diff)
cli: share timer elapsed-state check helper
Diffstat (limited to 'internal/cli/timer.go')
-rw-r--r--internal/cli/timer.go34
1 files changed, 20 insertions, 14 deletions
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
+}