mirror of
https://github.com/runkids/skillshare.git
synced 2026-11-20 20:34:19 +00:00
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.
This commit is contained in:
@@ -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 {
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user