Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 3 additions & 11 deletions cmd/compatibility/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package compatibility
import (
"fmt"
"os"
"slices"
"strings"

"github.com/docker/compose/v5/cmd/compose"
Expand Down Expand Up @@ -59,7 +60,7 @@ func Convert(args []string) []string {
ARGS:
for i := 0; i < l; i++ {
arg := args[i]
if contains(getCompletionCommands(), arg) {
if slices.Contains(getCompletionCommands(), arg) {
command = append([]string{arg}, command...)
continue
}
Expand All @@ -79,7 +80,7 @@ ARGS:
arg = "version"
}

if contains(getBoolFlags(), arg) {
if slices.Contains(getBoolFlags(), arg) {
rootFlags = append(rootFlags, arg)
continue
}
Expand All @@ -105,12 +106,3 @@ ARGS:
}
return append(rootFlags, command...)
}

func contains(array []string, needle string) bool {
for _, val := range array {
if val == needle {
return true
}
}
return false
}
5 changes: 2 additions & 3 deletions cmd/compose/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"fmt"
"io"
"os"
"slices"
"sort"
"strings"

Expand Down Expand Up @@ -454,9 +455,7 @@ func runHash(ctx context.Context, dockerCli command.Cli, opts configOptions) err
}

sorted := services
sort.Slice(sorted, func(i, j int) bool {
return sorted[i] < sorted[j]
})
slices.Sort(sorted)

for _, name := range sorted {
s, err := project.GetService(name)
Expand Down
11 changes: 1 addition & 10 deletions cmd/compose/ps.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,18 +167,9 @@ func runPs(ctx context.Context, dockerCli command.Cli, backendOptions *BackendOp
func filterByStatus(containers []api.ContainerSummary, statuses []string) []api.ContainerSummary {
var filtered []api.ContainerSummary
for _, c := range containers {
if hasStatus(c, statuses) {
if slices.Contains(statuses, string(c.State)) {
filtered = append(filtered, c)
}
}
return filtered
}

func hasStatus(c api.ContainerSummary, statuses []string) bool {
for _, status := range statuses {
if string(c.State) == status {
return true
}
}
return false
}
30 changes: 6 additions & 24 deletions cmd/display/tty.go
Original file line number Diff line number Diff line change
Expand Up @@ -317,10 +317,7 @@ func (w *ttyWriter) printWithDimensions(terminalWidth, terminalHeight int) {
allTasks := slices.Collect(w.parentTasks())

// Available lines: terminal height - 2 (header line + potential "more" line)
maxLines := terminalHeight - 2
if maxLines < 1 {
maxLines = 1
}
maxLines := max(terminalHeight-2, 1)

showMore := len(allTasks) > maxLines
tasksToShow := allTasks
Expand Down Expand Up @@ -354,10 +351,7 @@ func (w *ttyWriter) printWithDimensions(terminalWidth, terminalHeight int) {
if showMore {
moreCount := len(allTasks) - len(tasksToShow)
moreText := fmt.Sprintf(" ... %d more", moreCount)
pad := terminalWidth - len(moreText)
if pad < 0 {
pad = 0
}
pad := max(terminalWidth-len(moreText), 0)
_, _ = fmt.Fprintf(w.out, "%s%s\n", moreText, strings.Repeat(" ", pad))
numLines++
}
Expand Down Expand Up @@ -392,10 +386,7 @@ func (w *ttyWriter) applyPadding(lines []lineData, terminalWidth int, timerLen i
if l.details != "" {
lineLen += 1 + utf8.RuneCountInString(l.details)
}
l.timerPad = terminalWidth - lineLen - timerLen
if l.timerPad < 1 {
l.timerPad = 1
}
l.timerPad = max(terminalWidth-lineLen-timerLen, 1)
lines[i] = l

}
Expand Down Expand Up @@ -472,10 +463,7 @@ func truncateDetails(lines []lineData, overflow int) bool {
for i := range lines {
l := &lines[i]
if len(l.details) > 3 {
reduction := overflow
if reduction > len(l.details)-3 {
reduction = len(l.details) - 3
}
reduction := min(overflow, len(l.details)-3)
l.details = l.details[:len(l.details)-reduction-3] + "..."
return true
} else if l.details != "" {
Expand Down Expand Up @@ -504,10 +492,7 @@ func truncateLongestTaskID(lines []lineData, overflow, minIDLen int) bool {

l := &lines[longestIdx]
reduction := overflow + 3 // account for "..."
newLen := len(l.taskID) - reduction
if newLen < minIDLen-3 {
newLen = minIDLen - 3
}
newLen := max(len(l.taskID)-reduction, minIDLen-3)
if newLen > 0 {
l.taskID = l.taskID[:newLen] + "..."
}
Expand Down Expand Up @@ -546,10 +531,7 @@ func (w *ttyWriter) prepareLineData(t *task) lineData {
total += child.total
current += child.current
r := len(percentChars) - 1
p := child.percent
if p > 100 {
p = 100
}
p := min(child.percent, 100)
completion = append(completion, percentChars[r*p/100])
}
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/display/tty_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ func TestPrintWithDimensions_TaskWithProgress(t *testing.T) {
w.ids = append(w.ids, "Image nginx")

// Create child tasks to trigger progress display
for i := 0; i < 3; i++ {
for i := range 3 {
child := &task{
ID: "layer" + string(rune('a'+i)),
parents: map[string]struct{}{"Image nginx": {}},
Expand Down
4 changes: 2 additions & 2 deletions cmd/formatter/shortcut.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ func (lk *LogKeyboard) clearNavigationMenu() {
saveCursor()

// clearLine()
for i := 0; i < height; i++ {
for range height {
moveCursorDown(1)
clearLine()
}
Expand Down Expand Up @@ -341,7 +341,7 @@ func (lk *LogKeyboard) EnableDetach(detach func()) {
}

func allocateSpace(lines int) {
for i := 0; i < lines; i++ {
for range lines {
clearLine()
newLine()
carriageReturn()
Expand Down
12 changes: 4 additions & 8 deletions internal/tracing/mux.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,13 @@ func (m MuxExporter) ExportSpans(ctx context.Context, spans []sdktrace.ReadOnlyS
)

for _, exporter := range m.exporters {
wg.Add(1)
go func() {
defer wg.Done()
wg.Go(func() {
if err := exporter.ExportSpans(ctx, spans); err != nil {
errMu.Lock()
errs = append(errs, err)
errMu.Unlock()
}
}()
})
}
wg.Wait()
return errors.Join(errs...)
Expand All @@ -58,15 +56,13 @@ func (m MuxExporter) Shutdown(ctx context.Context) error {
)

for _, exporter := range m.exporters {
wg.Add(1)
go func() {
defer wg.Done()
wg.Go(func() {
if err := exporter.Shutdown(ctx); err != nil {
errMu.Lock()
errs = append(errs, err)
errMu.Unlock()
}
}()
})
}
wg.Wait()
return errors.Join(errs...)
Expand Down
5 changes: 1 addition & 4 deletions pkg/compose/pull.go
Original file line number Diff line number Diff line change
Expand Up @@ -430,10 +430,7 @@ func toPullProgressEvent(parent string, jm jsonstream.Message, events api.EventP
current = jm.Progress.Current
total = jm.Progress.Total
if jm.Progress.Total > 0 {
percent = int(jm.Progress.Current * 100 / jm.Progress.Total)
if percent > 100 {
percent = 100
}
percent = min(int(jm.Progress.Current*100/jm.Progress.Total), 100)
}
}
case DownloadCompletePhase, AlreadyExistsPhase, PullCompletePhase:
Expand Down
5 changes: 1 addition & 4 deletions pkg/compose/push.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,10 +155,7 @@ func toPushProgressEvent(prefix string, jm jsonstream.Message, events api.EventP
current = jm.Progress.Current
total = jm.Progress.Total
if jm.Progress.Total > 0 {
percent = int(jm.Progress.Current * 100 / jm.Progress.Total)
if percent > 100 {
percent = 100
}
percent = min(int(jm.Progress.Current*100/jm.Progress.Total), 100)
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/e2e/logs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ func TestLocalComposeLargeLogs(t *testing.T) {

f, err := os.Create(file)
assert.NilError(t, err)
for i := 0; i < 300_000; i++ {
for i := range 300_000 {
_, err := io.WriteString(f, fmt.Sprintf("This is line %d in a laaaarge text file\n", i))
assert.NilError(t, err)
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/watch/debounce_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func Test_BatchDebounceEvents(t *testing.T) {
t.Cleanup(stop)

eventBatchCh := BatchDebounceEvents(ctx, clock, ch)
for i := 0; i < 100; i++ {
for i := range 100 {
path := "/a"
if i%2 == 0 {
path = "/b"
Expand Down
2 changes: 1 addition & 1 deletion pkg/watch/notify_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ func TestGitBranchSwitch(t *testing.T) {
done := f.consumeEventsInBackground(ctx)

for i, dir := range dirs {
for j := 0; j < count; j++ {
for j := range count {
base := fmt.Sprintf("x/y/dir-%d/x.txt", j)
p := filepath.Join(dir, base)
f.WriteFile(p, "contents")
Expand Down
8 changes: 4 additions & 4 deletions pkg/watch/watcher_naive_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func TestDontWatchEachFile(t *testing.T) {
t.Fatal(err)
}

for i := 0; i < 100; i++ {
for i := range 100 {
f.WriteFile(f.JoinPath(initialDir, fmt.Sprintf("%d", i)), "initial data")
}

Expand All @@ -79,7 +79,7 @@ func TestDontWatchEachFile(t *testing.T) {
t.Fatal(err)
}

for i := 0; i < 100; i++ {
for i := range 100 {
f.WriteFile(f.JoinPath(inplaceDir, fmt.Sprintf("%d", i)), "inplace data")
}

Expand All @@ -98,7 +98,7 @@ func TestDontWatchEachFile(t *testing.T) {
t.Fatal(err)
}

for i := 0; i < 100; i++ {
for i := range 100 {
f.WriteFile(f.JoinPath(stagedDir, fmt.Sprintf("%d", i)), "staged data")
}

Expand Down Expand Up @@ -146,7 +146,7 @@ func TestDontRecurseWhenWatchingParentsOfNonExistentFiles(t *testing.T) {
f.watch(filepath.Join(watched, ".tiltignore"))

excludedDir := f.JoinPath(watched, "excluded")
for i := 0; i < 10; i++ {
for i := range 10 {
f.WriteFile(f.JoinPath(excludedDir, fmt.Sprintf("%d", i), "data.txt"), "initial data")
}
f.fsync()
Expand Down