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
2 changes: 1 addition & 1 deletion cli-plugins/manager/candidate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ func TestValidateCandidate(t *testing.T) {
assert.ErrorContains(t, err, tc.err)
case tc.invalid != "":
assert.NilError(t, err)
assert.Assert(t, is.ErrorType(p.Err, reflect.TypeOf(&pluginError{})))
assert.Assert(t, is.ErrorType(p.Err, reflect.TypeFor[*pluginError]()))
assert.ErrorContains(t, p.Err, tc.invalid)
default:
assert.NilError(t, err)
Expand Down
6 changes: 4 additions & 2 deletions cli-plugins/manager/hooks.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// FIXME(thaJeztah): remove once we are a module; the go:build directive prevents go from downgrading language version to go1.16:
//go:build go1.24

package manager

import (
Expand Down Expand Up @@ -141,8 +144,7 @@ func pluginMatch(pluginCfg map[string]string, subCmd string) (string, bool) {
return "", false
}

commands := strings.Split(configuredPluginHooks, ",")
for _, hookCmd := range commands {
for hookCmd := range strings.SplitSeq(configuredPluginHooks, ",") {
if hookMatch(hookCmd, subCmd) {
return hookCmd, true
}
Expand Down
2 changes: 1 addition & 1 deletion cli/command/container/opts.go
Original file line number Diff line number Diff line change
Expand Up @@ -902,7 +902,7 @@ func convertToStandardNotation(ports []string) ([]string, error) {
for _, publish := range ports {
if strings.Contains(publish, "=") {
params := map[string]string{"protocol": "tcp"}
for _, param := range strings.Split(publish, ",") {
for param := range strings.SplitSeq(publish, ",") {
k, v, ok := strings.Cut(param, "=")
if !ok || k == "" {
return optsList, fmt.Errorf("invalid publish opts format (should be name=value but got '%s')", param)
Expand Down
2 changes: 1 addition & 1 deletion cli/command/container/run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ func TestRunPullTermination(t *testing.T) {
go func() {
id := test.RandomID()[:12] // short-ID
progressOutput := streamformatter.NewJSONProgressOutput(server, true)
for i := 0; i < 100; i++ {
for i := range 100 {
select {
case <-ctx.Done():
assert.NilError(t, server.Close(), "failed to close imageCreateFunc server")
Expand Down
3 changes: 1 addition & 2 deletions cli/command/container/signals_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ import (
)

func TestForwardSignals(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
ctx := t.Context()

called := make(chan struct{})
apiClient := &fakeClient{containerKillFunc: func(ctx context.Context, container string, options client.ContainerKillOptions) (client.ContainerKillResult, error) {
Expand Down
5 changes: 4 additions & 1 deletion cli/command/container/stats.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// FIXME(thaJeztah): remove once we are a module; the go:build directive prevents go from downgrading language version to go1.16:
//go:build go1.24

package container

import (
Expand Down Expand Up @@ -337,7 +340,7 @@ func RunStats(ctx context.Context, dockerCLI command.Cli, options *StatsOptions)
return err
}

for _, line := range strings.Split(statsTextBuffer.String(), "\n") {
for line := range strings.SplitSeq(statsTextBuffer.String(), "\n") {
// In case the new text is shorter than the one we are writing over,
// we'll append the "erase line" escape sequence to clear the remaining text.
_, _ = fmt.Fprintln(&statsTextBuffer, line, "\033[K")
Expand Down
2 changes: 1 addition & 1 deletion cli/command/container/tty.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func initTtySize(ctx context.Context, cli command.Cli, id string, isExec bool, r
if err := rTTYfunc(ctx, cli, id, isExec); err != nil {
go func() {
var err error
for retry := 0; retry < 10; retry++ {
for retry := range 10 {
time.Sleep(time.Duration(retry+1) * 10 * time.Millisecond)
if err = rTTYfunc(ctx, cli, id, isExec); err == nil {
break
Expand Down
5 changes: 2 additions & 3 deletions cli/command/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package command
import (
"encoding/json"
"errors"
"maps"

"github.com/docker/cli/cli/context/store"
)
Expand All @@ -23,9 +24,7 @@ func (dc DockerContext) MarshalJSON() ([]byte, error) {
s["Description"] = dc.Description
}
if dc.AdditionalFields != nil {
for k, v := range dc.AdditionalFields {
s[k] = v
}
maps.Copy(s, dc.AdditionalFields)
}
return json.Marshal(s)
}
Expand Down
10 changes: 5 additions & 5 deletions cli/command/formatter/tabwriter/tabwriter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func (b *buffer) Write(buf []byte) (written int, err error) {
m := len(buf)
if n+m <= cap(b.a) {
b.a = b.a[0 : n+m]
for i := 0; i < m; i++ {
for i := range m {
b.a[n+i] = buf[i]
}
} else {
Expand Down Expand Up @@ -669,7 +669,7 @@ func BenchmarkTable(b *testing.B) {
for i := 0; i < b.N; i++ {
w := NewWriter(io.Discard, 4, 4, 1, ' ', 0) // no particular reason for these settings
// Write the line h times.
for j := 0; j < h; j++ {
for range h {
w.Write(line)
}
w.Flush()
Expand All @@ -681,7 +681,7 @@ func BenchmarkTable(b *testing.B) {
w := NewWriter(io.Discard, 4, 4, 1, ' ', 0) // no particular reason for these settings
for i := 0; i < b.N; i++ {
// Write the line h times.
for j := 0; j < h; j++ {
for range h {
w.Write(line)
}
w.Flush()
Expand All @@ -701,7 +701,7 @@ func BenchmarkPyramid(b *testing.B) {
for i := 0; i < b.N; i++ {
w := NewWriter(io.Discard, 4, 4, 1, ' ', 0) // no particular reason for these settings
// Write increasing prefixes of that line.
for j := 0; j < x; j++ {
for j := range x {
w.Write(line[:j*2])
w.Write([]byte{'\n'})
}
Expand All @@ -723,7 +723,7 @@ func BenchmarkRagged(b *testing.B) {
for i := 0; i < b.N; i++ {
w := NewWriter(io.Discard, 4, 4, 1, ' ', 0) // no particular reason for these settings
// Write the lines in turn h times.
for j := 0; j < h; j++ {
for j := range h {
w.Write(lines[j%len(lines)])
w.Write([]byte{'\n'})
}
Expand Down
2 changes: 1 addition & 1 deletion cli/command/idresolver/idresolver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func TestResolveWithCache(t *testing.T) {
idResolver := New(apiClient, false)

ctx := context.Background()
for i := 0; i < 2; i++ {
for range 2 {
id, err := idResolver.Resolve(ctx, swarm.Node{}, "nodeID")
assert.NilError(t, err)
assert.Check(t, is.Equal("node-foo", id))
Expand Down
5 changes: 1 addition & 4 deletions cli/command/image/tree.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
10 changes: 6 additions & 4 deletions cli/command/manifest/annotate.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
// FIXME(thaJeztah): remove once we are a module; the go:build directive prevents go from downgrading language version to go1.16:
//go:build go1.24

package manifest

import (
"context"
"fmt"
"path/filepath"
"slices"

"github.com/containerd/errdefs"
"github.com/docker/cli/cli"
Expand Down Expand Up @@ -164,10 +168,8 @@ func runManifestAnnotate(dockerCLI command.Cli, opts annotateOptions) error {
}

func appendIfUnique(list []string, str string) []string {
for _, s := range list {
if s == str {
return list
}
if slices.Contains(list, str) {
return list
}
return append(list, str)
}
8 changes: 5 additions & 3 deletions cli/command/node/update.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
// FIXME(thaJeztah): remove once we are a module; the go:build directive prevents go from downgrading language version to go1.16:
//go:build go1.24

package node

import (
"context"
"errors"
"fmt"
"maps"

"github.com/docker/cli/cli"
"github.com/docker/cli/cli/command"
Expand Down Expand Up @@ -99,9 +103,7 @@ func mergeNodeUpdate(flags *pflag.FlagSet) func(*swarm.Node) error {
}
if flags.Changed(flagLabelAdd) {
labels := flags.Lookup(flagLabelAdd).Value.(*opts.ListOpts).GetSlice()
for k, v := range opts.ConvertKVStringsToMap(labels) {
spec.Annotations.Labels[k] = v
}
maps.Copy(spec.Annotations.Labels, opts.ConvertKVStringsToMap(labels))
}
if flags.Changed(flagLabelRemove) {
keys := flags.Lookup(flagLabelRemove).Value.(*opts.ListOpts).GetSlice()
Expand Down
7 changes: 2 additions & 5 deletions cli/command/service/list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -279,7 +276,7 @@ func generateNodes(t *testing.T, activeNodes uint64) client.NodeListResult {
t.Helper()
nodes := client.NodeListResult{}
var i uint64
for i = 0; i < activeNodes; i++ {
for i = range activeNodes {
nodes.Items = append(nodes.Items, swarm.Node{
ID: fmt.Sprintf("node-ready-%d", i),
Status: swarm.NodeStatus{State: swarm.NodeStateReady},
Expand Down
5 changes: 1 addition & 4 deletions cli/command/service/progress/progress.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion cli/command/service/progress/progress_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -856,7 +856,7 @@ func TestGlobalJobProgressUpdaterLarge(t *testing.T) {
}

activeNodes := map[string]struct{}{}
for i := 0; i < 50; i++ {
for i := range 50 {
activeNodes[fmt.Sprintf("node%v", i)] = struct{}{}
}

Expand Down
20 changes: 5 additions & 15 deletions cli/command/service/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"context"
"errors"
"fmt"
"maps"
"net/netip"
"slices"
"sort"
Expand Down Expand Up @@ -551,12 +552,7 @@ func updateStringToSlice(flags *pflag.FlagSet, flag string, field *[]string) {
}

func anyChanged(flags *pflag.FlagSet, fields ...string) bool {
for _, flag := range fields {
if flags.Changed(flag) {
return true
}
}
return false
return slices.ContainsFunc(fields, flags.Changed)
}

func addGenericResources(flags *pflag.FlagSet, spec *swarm.TaskSpec) error {
Expand Down Expand Up @@ -685,9 +681,7 @@ func updateContainerLabels(flags *pflag.FlagSet, field *map[string]string) {
}

values := flags.Lookup(flagContainerLabelAdd).Value.(*opts.ListOpts).GetSlice()
for key, value := range opts.ConvertKVStringsToMap(values) {
(*field)[key] = value
}
maps.Copy((*field), opts.ConvertKVStringsToMap(values))
}
}

Expand All @@ -704,9 +698,7 @@ func updateLabels(flags *pflag.FlagSet, field *map[string]string) {
}

values := flags.Lookup(flagLabelAdd).Value.(*opts.ListOpts).GetSlice()
for key, value := range opts.ConvertKVStringsToMap(values) {
(*field)[key] = value
}
maps.Copy((*field), opts.ConvertKVStringsToMap(values))
}
}

Expand All @@ -723,9 +715,7 @@ func updateSysCtls(flags *pflag.FlagSet, field *map[string]string) {
}

values := flags.Lookup(flagSysCtlAdd).Value.(*opts.ListOpts).GetSlice()
for key, value := range opts.ConvertKVStringsToMap(values) {
(*field)[key] = value
}
maps.Copy((*field), opts.ConvertKVStringsToMap(values))
}
}

Expand Down
6 changes: 3 additions & 3 deletions cli/command/telemetry_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,11 +155,11 @@ func (e statusError) Error() string {
// Note: The root command's name is excluded. If cmd is the root cmd, return ""
func getCommandName(cmd *cobra.Command) string {
fullCmdName := getFullCommandName(cmd)
i := strings.Index(fullCmdName, " ")
if i == -1 {
_, after, ok := strings.Cut(fullCmdName, " ")
if !ok {
return ""
}
return fullCmdName[i+1:]
return after
}

// getFullCommandName gets the full cobra command name in the format
Expand Down
7 changes: 5 additions & 2 deletions cli/command/volume/create.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// FIXME(thaJeztah): remove once we are a module; the go:build directive prevents go from downgrading language version to go1.16:
//go:build go1.24

package volume

import (
Expand Down Expand Up @@ -166,7 +169,7 @@ func runCreate(ctx context.Context, dockerCli command.Cli, options createOptions
// each topology takes the form segment=value,segment=value
// comma-separated list of equal separated maps
segments := map[string]string{}
for _, segment := range strings.Split(top, ",") {
for segment := range strings.SplitSeq(top, ",") {
// TODO(dperny): validate topology syntax
k, v, _ := strings.Cut(segment, "=")
segments[k] = v
Expand All @@ -181,7 +184,7 @@ func runCreate(ctx context.Context, dockerCli command.Cli, options createOptions
// each topology takes the form segment=value,segment=value
// comma-separated list of equal separated maps
segments := map[string]string{}
for _, segment := range strings.Split(top, ",") {
for segment := range strings.SplitSeq(top, ",") {
// TODO(dperny): validate topology syntax
k, v, _ := strings.Cut(segment, "=")
segments[k] = v
Expand Down
5 changes: 2 additions & 3 deletions cli/compose/loader/loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package loader
import (
"errors"
"fmt"
"maps"
"path"
"path/filepath"
"reflect"
Expand Down Expand Up @@ -249,9 +250,7 @@ func GetDeprecatedProperties(configDicts ...map[string]any) map[string]string {

for _, configDict := range configDicts {
deprecatedProperties := getProperties(getServices(configDict), types.DeprecatedProperties)
for key, value := range deprecatedProperties {
deprecated[key] = value
}
maps.Copy(deprecated, deprecatedProperties)
}

return deprecated
Expand Down
4 changes: 2 additions & 2 deletions cli/compose/loader/merge_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1153,7 +1153,7 @@ func TestLoadMultipleServiceVolumes(t *testing.T) {
func TestMergeUlimitsConfig(t *testing.T) {
specials := &specials{
m: map[reflect.Type]func(dst, src reflect.Value) error{
reflect.TypeOf(&types.UlimitsConfig{}): mergeUlimitsConfig,
reflect.TypeFor[*types.UlimitsConfig](): mergeUlimitsConfig,
},
}
base := map[string]*types.UlimitsConfig{
Expand Down Expand Up @@ -1189,7 +1189,7 @@ func TestMergeUlimitsConfig(t *testing.T) {
func TestMergeServiceNetworkConfig(t *testing.T) {
specials := &specials{
m: map[reflect.Type]func(dst, src reflect.Value) error{
reflect.TypeOf(&types.ServiceNetworkConfig{}): mergeServiceNetworkConfig,
reflect.TypeFor[*types.ServiceNetworkConfig](): mergeServiceNetworkConfig,
},
}
base := map[string]*types.ServiceNetworkConfig{
Expand Down
Loading
Loading