summaryrefslogtreecommitdiff
path: root/internal/commands/in.go
diff options
context:
space:
mode:
authorT <t@tjp.lol>2025-09-29 15:04:44 -0600
committerT <t@tjp.lol>2025-09-30 11:40:45 -0600
commit7ba68d333bc20b5795ccfd3870546a05eee60470 (patch)
tree12dc4b017803b7d01844fd42b9e3be281cbbd986 /internal/commands/in.go
parentbce8dbb58165e443902d9dae3909225ef42630c4 (diff)
Support for archiving clients and projects.HEADmain
Diffstat (limited to 'internal/commands/in.go')
-rw-r--r--internal/commands/in.go38
1 files changed, 33 insertions, 5 deletions
diff --git a/internal/commands/in.go b/internal/commands/in.go
index 8c5025a..8a08edf 100644
--- a/internal/commands/in.go
+++ b/internal/commands/in.go
@@ -1,6 +1,7 @@
package commands
import (
+ "errors"
"fmt"
"git.tjp.lol/punchcard/internal/actions"
@@ -54,16 +55,43 @@ Examples:
var session *actions.TimerSession
var err error
+ // Try punching in without auto-unarchive first
if clientFlag == "" && projectFlag == "" {
- // Use most recent entry
- session, err = a.PunchInMostRecent(cmd.Context(), description, billableRate)
+ session, err = a.PunchInMostRecent(cmd.Context(), description, billableRate, false)
} else {
- // Use specified client/project
- session, err = a.PunchIn(cmd.Context(), clientFlag, projectFlag, description, billableRate)
+ session, err = a.PunchIn(cmd.Context(), clientFlag, projectFlag, description, billableRate, false)
}
+ // Handle archived errors by prompting user
if err != nil {
- return err
+ if errors.Is(err, actions.ErrArchivedClient) || errors.Is(err, actions.ErrArchivedProject) {
+ entityType := "client"
+ if errors.Is(err, actions.ErrArchivedProject) {
+ entityType = "project"
+ }
+
+ cmd.Printf("Warning: This %s is archived.\n", entityType)
+ cmd.Print("Continue and unarchive? (y/N): ")
+
+ var response string
+ _, err := fmt.Scanln(&response)
+ if err != nil || (response != "y" && response != "Y") {
+ return fmt.Errorf("operation cancelled")
+ }
+
+ // Retry with auto-unarchive enabled
+ if clientFlag == "" && projectFlag == "" {
+ session, err = a.PunchInMostRecent(cmd.Context(), description, billableRate, true)
+ } else {
+ session, err = a.PunchIn(cmd.Context(), clientFlag, projectFlag, description, billableRate, true)
+ }
+
+ if err != nil {
+ return err
+ }
+ } else {
+ return err
+ }
}
// Handle different response types