summaryrefslogtreecommitdiff
path: root/internal/commands/in.go
diff options
context:
space:
mode:
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