Skip to content

Commit c8b64a4

Browse files
committed
pr feedback
1 parent c375949 commit c8b64a4

2 files changed

Lines changed: 34 additions & 10 deletions

File tree

cmd/entire/cli/clean.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package cli
22

33
import (
44
"context"
5+
"errors"
56
"fmt"
67
"io"
78
"os"
@@ -50,13 +51,14 @@ The entire/checkpoints/v1 branch itself is never deleted.`,
5051
},
5152
}
5253

53-
cmd.Flags().BoolVarP(&forceFlag, "force", "f", false, "Actually delete items (default: dry run)")
54+
cmd.Flags().BoolVarP(&forceFlag, "force", "f", false, "Delete without prompting for confirmation")
5455

5556
return cmd
5657
}
5758

5859
func runClean(ctx context.Context, cmd *cobra.Command, force bool) error {
5960
w := cmd.OutOrStdout()
61+
errW := cmd.ErrOrStderr()
6062

6163
// Initialize logging so structured logs go to .entire/logs/ instead of stderr.
6264
// Error is non-fatal: if logging init fails, logs go to stderr (acceptable fallback).
@@ -75,7 +77,7 @@ func runClean(ctx context.Context, cmd *cobra.Command, force bool) error {
7577
tempFiles, err := listTempFiles(ctx)
7678
if err != nil {
7779
// Non-fatal: continue with other cleanup items
78-
fmt.Fprintf(w, "Warning: failed to list temp files: %v\n", err)
80+
fmt.Fprintf(errW, "Warning: failed to list temp files: %v\n", err)
7981
}
8082

8183
// Force mode: skip preview and confirmation
@@ -107,7 +109,10 @@ func runClean(ctx context.Context, cmd *cobra.Command, force bool) error {
107109
)
108110

109111
if err := form.Run(); err != nil {
110-
return fmt.Errorf("confirmation cancelled: %w", err)
112+
if errors.Is(err, huh.ErrUserAborted) {
113+
return nil
114+
}
115+
return fmt.Errorf("confirmation failed: %w", err)
111116
}
112117

113118
if !confirmed {

cmd/entire/cli/rewind.go

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,10 @@ func runRewindInteractive(ctx context.Context, w, errW io.Writer) error { //noli
161161
)
162162

163163
if err := form.Run(); err != nil {
164-
return fmt.Errorf("selection cancelled: %w", err)
164+
if errors.Is(err, huh.ErrUserAborted) {
165+
return nil
166+
}
167+
return fmt.Errorf("selection failed: %w", err)
165168
}
166169

167170
if selectedID == "cancel" {
@@ -208,7 +211,9 @@ func runRewindInteractive(ctx context.Context, w, errW io.Writer) error { //noli
208211

209212
// Preview rewind to show warnings about files that will be deleted
210213
preview, previewErr := start.PreviewRewind(ctx, *selectedPoint)
211-
if previewErr == nil && preview != nil && len(preview.FilesToDelete) > 0 {
214+
if previewErr != nil {
215+
fmt.Fprintf(errW, "Warning: could not preview rewind effects: %v\n", previewErr)
216+
} else if preview != nil && len(preview.FilesToDelete) > 0 {
212217
fmt.Fprintf(errW, "\nWarning: The following untracked files will be DELETED:\n")
213218
for _, f := range preview.FilesToDelete {
214219
fmt.Fprintf(errW, " - %s\n", f)
@@ -229,7 +234,10 @@ func runRewindInteractive(ctx context.Context, w, errW io.Writer) error { //noli
229234
)
230235

231236
if err := confirmForm.Run(); err != nil {
232-
return fmt.Errorf("confirmation cancelled: %w", err)
237+
if errors.Is(err, huh.ErrUserAborted) {
238+
return nil
239+
}
240+
return fmt.Errorf("confirmation failed: %w", err)
233241
}
234242

235243
if !confirm {
@@ -433,7 +441,9 @@ func runRewindToInternal(ctx context.Context, w, errW io.Writer, commitID string
433441

434442
// Preview rewind to show warnings about files that will be deleted
435443
preview, previewErr := start.PreviewRewind(ctx, *selectedPoint)
436-
if previewErr == nil && preview != nil && len(preview.FilesToDelete) > 0 {
444+
if previewErr != nil {
445+
fmt.Fprintf(errW, "Warning: could not preview rewind effects: %v\n", previewErr)
446+
} else if preview != nil && len(preview.FilesToDelete) > 0 {
437447
fmt.Fprintf(errW, "\nWarning: The following untracked files will be DELETED:\n")
438448
for _, f := range preview.FilesToDelete {
439449
fmt.Fprintf(errW, " - %s\n", f)
@@ -798,7 +808,10 @@ func handleLogsOnlyRewindInteractive(ctx context.Context, w, errW io.Writer, sta
798808
)
799809

800810
if err := form.Run(); err != nil {
801-
return fmt.Errorf("action selection cancelled: %w", err)
811+
if errors.Is(err, huh.ErrUserAborted) {
812+
return nil
813+
}
814+
return fmt.Errorf("action selection failed: %w", err)
802815
}
803816

804817
switch action {
@@ -891,7 +904,10 @@ func handleLogsOnlyCheckout(ctx context.Context, w, errW io.Writer, start *strat
891904
)
892905

893906
if err := confirmForm.Run(); err != nil {
894-
return fmt.Errorf("confirmation cancelled: %w", err)
907+
if errors.Is(err, huh.ErrUserAborted) {
908+
return nil
909+
}
910+
return fmt.Errorf("confirmation failed: %w", err)
895911
}
896912

897913
if !confirm {
@@ -986,7 +1002,10 @@ func handleLogsOnlyReset(ctx context.Context, w, errW io.Writer, start *strategy
9861002
)
9871003

9881004
if err := confirmForm.Run(); err != nil {
989-
return fmt.Errorf("confirmation cancelled: %w", err)
1005+
if errors.Is(err, huh.ErrUserAborted) {
1006+
return nil
1007+
}
1008+
return fmt.Errorf("confirmation failed: %w", err)
9901009
}
9911010

9921011
if !confirm {

0 commit comments

Comments
 (0)