diff --git a/cli/command/image/tree.go b/cli/command/image/tree.go index 70b7482867..6616e9e207 100644 --- a/cli/command/image/tree.go +++ b/cli/command/image/tree.go @@ -389,10 +389,7 @@ func generateLegend(out tui.Output, width uint) string { } legend += legendSb371.String() - r := int(width) - tui.Width(legend) - if r < 0 { - r = 0 - } + r := max(int(width)-tui.Width(legend), 0) legend = strings.Repeat(" ", r) + legend return legend } diff --git a/cli/command/service/list_test.go b/cli/command/service/list_test.go index 8d6462e0bd..78bedbac51 100644 --- a/cli/command/service/list_test.go +++ b/cli/command/service/list_test.go @@ -191,10 +191,7 @@ func generateServices(t *testing.T, opts clusterOpts) client.ServiceListResult { t.Helper() // Can't have more global tasks than nodes - globalTasks := opts.runningTasks - if globalTasks > opts.activeNodes { - globalTasks = opts.activeNodes - } + globalTasks := min(opts.runningTasks, opts.activeNodes) return client.ServiceListResult{ Items: []swarm.Service{ *builders.Service( diff --git a/cli/command/service/progress/progress.go b/cli/command/service/progress/progress.go index a4de39b8fb..94b59d950e 100644 --- a/cli/command/service/progress/progress.go +++ b/cli/command/service/progress/progress.go @@ -662,10 +662,7 @@ func (u *replicatedJobProgressUpdater) writeOverallProgress(active, completed in }) // actualDesired is the lesser of MaxConcurrent, or the remaining tasks - actualDesired := u.total - completed - if actualDesired > u.concurrent { - actualDesired = u.concurrent - } + actualDesired := min(u.total-completed, u.concurrent) _ = u.progressOut.WriteProgress(progress.Progress{ ID: "active tasks",