diff options
author | T <t@tjp.lol> | 2025-09-29 15:04:44 -0600 |
---|---|---|
committer | T <t@tjp.lol> | 2025-09-30 11:40:45 -0600 |
commit | 7ba68d333bc20b5795ccfd3870546a05eee60470 (patch) | |
tree | 12dc4b017803b7d01844fd42b9e3be281cbbd986 /internal/commands/in.go | |
parent | bce8dbb58165e443902d9dae3909225ef42630c4 (diff) |
Diffstat (limited to 'internal/commands/in.go')
-rw-r--r-- | internal/commands/in.go | 38 |
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 |