Skip to content

Commit d0b5ae8

Browse files
fix(cli/clean): return error on execute failure and show per-package summary
Previously Execute errors were swallowed and 'Clean complete!' was always printed. Now returns the error on failure and calls showCleanSummary to display which packages were removed vs failed. Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-opencode) Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
1 parent 53a4a35 commit d0b5ae8

1 file changed

Lines changed: 31 additions & 2 deletions

File tree

internal/cli/clean.go

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,15 +88,16 @@ func runClean(cmd *cobra.Command) error {
8888
}
8989
}
9090

91-
// Execute
9291
if err := cleaner.Execute(result, dryRun); err != nil {
93-
ui.Error(fmt.Sprintf("Some packages failed to remove: %v", err))
92+
showCleanSummary(result)
93+
return fmt.Errorf("some packages failed to remove: %w", err)
9494
}
9595

9696
fmt.Println()
9797
if dryRun {
9898
ui.Muted("Dry run complete — no changes were made.")
9999
} else {
100+
showCleanSummary(result)
100101
ui.Success("Clean complete!")
101102
}
102103
fmt.Println()
@@ -144,6 +145,34 @@ func cleanFromLocalSnapshot() (*cleaner.CleanResult, error) {
144145
return cleaner.DiffFromSnapshot(snap)
145146
}
146147

148+
func showCleanSummary(result *cleaner.CleanResult) {
149+
fmt.Println()
150+
if result.TotalRemoved() > 0 {
151+
ui.Success(fmt.Sprintf("Removed %d package(s):", result.TotalRemoved()))
152+
if len(result.RemovedFormulae) > 0 {
153+
fmt.Printf(" formulae: %s\n", strings.Join(result.RemovedFormulae, ", "))
154+
}
155+
if len(result.RemovedCasks) > 0 {
156+
fmt.Printf(" casks: %s\n", strings.Join(result.RemovedCasks, ", "))
157+
}
158+
if len(result.RemovedNpm) > 0 {
159+
fmt.Printf(" npm: %s\n", strings.Join(result.RemovedNpm, ", "))
160+
}
161+
}
162+
if result.TotalFailed() > 0 {
163+
ui.Warn(fmt.Sprintf("Failed to remove %d package(s):", result.TotalFailed()))
164+
if len(result.FailedFormulae) > 0 {
165+
fmt.Printf(" formulae: %s\n", strings.Join(result.FailedFormulae, ", "))
166+
}
167+
if len(result.FailedCasks) > 0 {
168+
fmt.Printf(" casks: %s\n", strings.Join(result.FailedCasks, ", "))
169+
}
170+
if len(result.FailedNpm) > 0 {
171+
fmt.Printf(" npm: %s\n", strings.Join(result.FailedNpm, ", "))
172+
}
173+
}
174+
}
175+
147176
func showCleanPreview(result *cleaner.CleanResult) {
148177
ui.Info(fmt.Sprintf("Found %d extra packages not in your config:", result.TotalExtra()))
149178
fmt.Println()

0 commit comments

Comments
 (0)