From 0f2d66e18a9fdb877fec4ecf4197cea10c6f1217 Mon Sep 17 00:00:00 2001 From: Willie Date: Fri, 27 Feb 2026 15:56:03 +0800 Subject: [PATCH] refactor(update): align batch summary with sync-style single-line format Replace verbose SuccessMsg summary with UpdateSummary() matching SyncSummary's clean single-line stats format with color coding. --- cmd/skillshare/update.go | 4 +-- cmd/skillshare/update_batch.go | 17 +++++----- cmd/skillshare/update_project.go | 6 ++-- internal/ui/pterm.go | 53 ++++++++++++++++++++++++++++++++ 4 files changed, 66 insertions(+), 14 deletions(-) diff --git a/cmd/skillshare/update.go b/cmd/skillshare/update.go index 129ffdaa0..1b299d64f 100644 --- a/cmd/skillshare/update.go +++ b/cmd/skillshare/update.go @@ -246,7 +246,7 @@ func cmdUpdate(args []string) error { skillCount++ } } - ui.StepContinue("Items", fmt.Sprintf("%d tracked repo(s), %d skill(s)", repoCount, skillCount)) + ui.StepEnd("Items", fmt.Sprintf("%d tracked repo(s), %d skill(s)", repoCount, skillCount)) for _, w := range resolveWarnings { ui.Warning("%s", w) @@ -254,7 +254,7 @@ func cmdUpdate(args []string) error { if len(targets) == 0 { if opts.all { - ui.SuccessMsg("Updated 0, skipped 0 of 0 skill(s)") + ui.UpdateSummary(ui.UpdateStats{}) return nil } if len(resolveWarnings) > 0 { diff --git a/cmd/skillshare/update_batch.go b/cmd/skillshare/update_batch.go index 9d5877d74..567fe316d 100644 --- a/cmd/skillshare/update_batch.go +++ b/cmd/skillshare/update_batch.go @@ -52,6 +52,7 @@ func (uc *updateContext) makeInstallOpts() install.InstallOptions { // Returns combined updateResult and any security error. func executeBatchUpdate(uc *updateContext, targets []updateTarget) (updateResult, error) { total := len(targets) + start := time.Now() fmt.Println() progressBar := ui.StartProgress("Updating skills", total) @@ -229,15 +230,13 @@ func executeBatchUpdate(uc *updateContext, targets []updateTarget) (updateResult displayPrunedSection(prunedNames) displayStaleWarning(staleNames) displayUpdateAuditResults(auditEntries, uc.opts.auditVerbose) - fmt.Println() - parts := []string{fmt.Sprintf("Updated %d, skipped %d", result.updated, result.skipped)} - if result.pruned > 0 { - parts = append(parts, fmt.Sprintf("pruned %d", result.pruned)) - } - ui.SuccessMsg("%s of %d skill(s)", strings.Join(parts, ", "), total) - if result.securityFailed > 0 { - ui.Warning("Blocked: %d (security)", result.securityFailed) - } + ui.UpdateSummary(ui.UpdateStats{ + Updated: result.updated, + Skipped: result.skipped, + Pruned: result.pruned, + SecurityFailed: result.securityFailed, + Duration: time.Since(start), + }) } if (result.updated > 0 || result.pruned > 0) && !uc.opts.dryRun { diff --git a/cmd/skillshare/update_project.go b/cmd/skillshare/update_project.go index dbe0fa1a3..5e075eca4 100644 --- a/cmd/skillshare/update_project.go +++ b/cmd/skillshare/update_project.go @@ -145,7 +145,7 @@ func cmdUpdateProjectBatch(sourcePath string, opts *updateOptions, projectRoot s skillCount++ } } - ui.StepContinue("Items", fmt.Sprintf("%d tracked repo(s), %d skill(s)", repoCount, skillCount)) + ui.StepEnd("Items", fmt.Sprintf("%d tracked repo(s), %d skill(s)", repoCount, skillCount)) for _, w := range resolveWarnings { ui.Warning("%s", w) @@ -229,11 +229,11 @@ func updateAllProjectSkills(uc *updateContext) error { skillCount++ } } - ui.StepContinue("Items", fmt.Sprintf("%d tracked repo(s), %d skill(s)", repoCount, skillCount)) + ui.StepEnd("Items", fmt.Sprintf("%d tracked repo(s), %d skill(s)", repoCount, skillCount)) total := len(targets) if total == 0 { - ui.SuccessMsg("Updated 0, skipped 0 of 0 skill(s)") + ui.UpdateSummary(ui.UpdateStats{}) return nil } diff --git a/internal/ui/pterm.go b/internal/ui/pterm.go index 58be354a1..021980cec 100644 --- a/internal/ui/pterm.go +++ b/internal/ui/pterm.go @@ -363,8 +363,13 @@ func StartProgress(title string, total int) *ProgressBar { } // Increment increments progress by 1. +// When the bar reaches 100%, the title is replaced with "Done" so the +// final render does not freeze on the last item name. func (p *ProgressBar) Increment() { if p.bar != nil { + if p.bar.Current+1 >= p.bar.Total { + p.UpdateTitle("Done") + } p.bar.Increment() } } @@ -492,6 +497,54 @@ type SyncStats struct { Duration time.Duration } +// UpdateSummary prints an update summary line matching SyncSummary style. +func UpdateSummary(stats UpdateStats) { + fmt.Println() // spacing + + if !IsTTY() { + fmt.Printf("Update complete: %d updated, %d skipped, %d pruned", + stats.Updated, stats.Skipped, stats.Pruned) + if stats.Duration > 0 { + fmt.Printf(" (%.1fs)", stats.Duration.Seconds()) + } + fmt.Println() + if stats.SecurityFailed > 0 { + fmt.Printf("Warning: %d repo(s) blocked by security audit\n", stats.SecurityFailed) + } + return + } + + skippedColor := pterm.Gray + if stats.Skipped > 0 { + skippedColor = pterm.Yellow + } + + line := fmt.Sprintf( + "%s %s updated %s skipped %s pruned", + pterm.Green("✓ Update complete"), + pterm.Green(fmt.Sprint(stats.Updated)), + skippedColor(fmt.Sprint(stats.Skipped)), + pterm.Yellow(fmt.Sprint(stats.Pruned)), + ) + if stats.Duration > 0 { + line += fmt.Sprintf(" %s", pterm.Gray(fmt.Sprintf("(%.1fs)", stats.Duration.Seconds()))) + } + fmt.Println(line) + + if stats.SecurityFailed > 0 { + Warning("Blocked: %d repo(s) by security audit", stats.SecurityFailed) + } +} + +// UpdateStats holds statistics for update summary +type UpdateStats struct { + Updated int + Skipped int + Pruned int + SecurityFailed int + Duration time.Duration +} + // ListItem prints a list item with status func ListItem(status, name, detail string) { var statusIcon string