Skip to content
Draft
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
9 changes: 6 additions & 3 deletions cli-plugins/manager/manager.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.26

package manager

import (
Expand All @@ -6,7 +9,7 @@ import (
"os"
"os/exec"
"path/filepath"
"sort"
slices "slices"
"strings"
"sync"

Expand Down Expand Up @@ -164,8 +167,8 @@ func ListPlugins(dockerCli config.Provider, rootcmd *cobra.Command) ([]Plugin, e
return nil, err
}

sort.Slice(plugins, func(i, j int) bool {
return sortorder.NaturalLess(plugins[i].Name, plugins[j].Name)
slices.SortFunc(plugins, func(a, b Plugin) int {
return sortorder.NaturalCompare(a.Name, b.Name)
})

return plugins, nil
Expand Down
9 changes: 6 additions & 3 deletions cli/cobra.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
// FIXME(thaJeztah): remove once we are a module; the go:build directive prevents go from downgrading language version to go1.16:
//go:build go1.26

package cli

import (
"fmt"
"os"
"sort"
"slices"
"strings"

"github.com/docker/cli/cli-plugins/metadata"
Expand Down Expand Up @@ -273,8 +276,8 @@ func topCommands(cmd *cobra.Command) []*cobra.Command {
cmds = append(cmds, sub)
}
}
sort.SliceStable(cmds, func(i, j int) bool {
return sortorder.NaturalLess(cmds[i].Annotations["category-top"], cmds[j].Annotations["category-top"])
slices.SortFunc(cmds, func(a, b *cobra.Command) int {
return sortorder.NaturalCompare(a.Annotations["category-top"], b.Annotations["category-top"])
})
return cmds
}
Expand Down
10 changes: 7 additions & 3 deletions cli/command/config/ls.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
// FIXME(thaJeztah): remove once we are a module; the go:build directive prevents go from downgrading language version to go1.16:
//go:build go1.26

package config

import (
"context"
"sort"
"slices"

"github.com/docker/cli/cli"
"github.com/docker/cli/cli/command"
"github.com/docker/cli/cli/command/formatter"
flagsHelper "github.com/docker/cli/cli/flags"
"github.com/docker/cli/opts"
"github.com/fvbommel/sortorder"
"github.com/moby/moby/api/types/swarm"
"github.com/moby/moby/client"
"github.com/spf13/cobra"
)
Expand Down Expand Up @@ -62,8 +66,8 @@ func runList(ctx context.Context, dockerCLI command.Cli, options listOptions) er
}
}

sort.Slice(res.Items, func(i, j int) bool {
return sortorder.NaturalLess(res.Items[i].Spec.Name, res.Items[j].Spec.Name)
slices.SortFunc(res.Items, func(a, b swarm.Config) int {
return sortorder.NaturalCompare(a.Spec.Name, b.Spec.Name)
})

configCtx := formatter.Context{
Expand Down
9 changes: 5 additions & 4 deletions cli/command/container/port.go
Original file line number Diff line number Diff line change
@@ -1,10 +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.26

package container

import (
"context"
"fmt"
"net"
"sort"
"slices"
"strings"

"github.com/docker/cli/cli"
Expand Down Expand Up @@ -80,9 +83,7 @@ func runPort(ctx context.Context, dockerCli command.Cli, opts *portOptions) erro
}

if len(out) > 0 {
sort.Slice(out, func(i, j int) bool {
return sortorder.NaturalLess(out[i], out[j])
})
slices.SortFunc(out, sortorder.NaturalCompare)
_, _ = fmt.Fprintln(dockerCli.Out(), strings.Join(out, "\n"))
}

Expand Down
6 changes: 3 additions & 3 deletions cli/command/context/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ package context
import (
"fmt"
"os"
"sort"
"slices"

"github.com/docker/cli/cli"
"github.com/docker/cli/cli/command"
Expand Down Expand Up @@ -101,8 +101,8 @@ func runList(dockerCli command.Cli, opts *listOptions) error {
Error: errMsg,
})
}
sort.Slice(contexts, func(i, j int) bool {
return sortorder.NaturalLess(contexts[i].Name, contexts[j].Name)
slices.SortFunc(contexts, func(a, b *formatter.ClientContext) int {
return sortorder.NaturalCompare(a.Name, b.Name)
})
if err := format(dockerCli, opts, contexts); err != nil {
return err
Expand Down
10 changes: 7 additions & 3 deletions cli/command/network/list.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
// FIXME(thaJeztah): remove once we are a module; the go:build directive prevents go from downgrading language version to go1.16:
//go:build go1.26

package network

import (
"context"
"sort"
"slices"

"github.com/docker/cli/cli"
"github.com/docker/cli/cli/command"
"github.com/docker/cli/cli/command/formatter"
flagsHelper "github.com/docker/cli/cli/flags"
"github.com/docker/cli/opts"
"github.com/fvbommel/sortorder"
"github.com/moby/moby/api/types/network"
"github.com/moby/moby/client"
"github.com/spf13/cobra"
)
Expand Down Expand Up @@ -61,8 +65,8 @@ func runList(ctx context.Context, dockerCLI command.Cli, options listOptions) er
}
}

sort.Slice(res.Items, func(i, j int) bool {
return sortorder.NaturalLess(res.Items[i].Name, res.Items[j].Name)
slices.SortFunc(res.Items, func(a, b network.Summary) int {
return sortorder.NaturalCompare(a.Name, b.Name)
})

networksCtx := formatter.Context{
Expand Down
10 changes: 7 additions & 3 deletions cli/command/node/list.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
// FIXME(thaJeztah): remove once we are a module; the go:build directive prevents go from downgrading language version to go1.16:
//go:build go1.26

package node

import (
"context"
"sort"
"slices"

"github.com/docker/cli/cli"
"github.com/docker/cli/cli/command"
"github.com/docker/cli/cli/command/formatter"
flagsHelper "github.com/docker/cli/cli/flags"
"github.com/docker/cli/opts"
"github.com/fvbommel/sortorder"
"github.com/moby/moby/api/types/swarm"
"github.com/moby/moby/client"
"github.com/spf13/cobra"
)
Expand Down Expand Up @@ -73,8 +77,8 @@ func runList(ctx context.Context, dockerCLI command.Cli, options listOptions) er
Output: dockerCLI.Out(),
Format: newFormat(format, options.quiet),
}
sort.Slice(res.Items, func(i, j int) bool {
return sortorder.NaturalLess(res.Items[i].Description.Hostname, res.Items[j].Description.Hostname)
slices.SortFunc(res.Items, func(a, b swarm.Node) int {
return sortorder.NaturalCompare(a.Description.Hostname, b.Description.Hostname)
})
return formatWrite(nodesCtx, res, info)
}
10 changes: 7 additions & 3 deletions cli/command/plugin/list.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
// FIXME(thaJeztah): remove once we are a module; the go:build directive prevents go from downgrading language version to go1.16:
//go:build go1.26

package plugin

import (
"context"
"sort"
"slices"

"github.com/docker/cli/cli"
"github.com/docker/cli/cli/command"
"github.com/docker/cli/cli/command/formatter"
flagsHelper "github.com/docker/cli/cli/flags"
"github.com/docker/cli/opts"
"github.com/fvbommel/sortorder"
"github.com/moby/moby/api/types/plugin"
"github.com/moby/moby/client"
"github.com/spf13/cobra"
)
Expand Down Expand Up @@ -54,8 +58,8 @@ func runList(ctx context.Context, dockerCli command.Cli, options listOptions) er
return err
}

sort.Slice(resp.Items, func(i, j int) bool {
return sortorder.NaturalLess(resp.Items[i].Name, resp.Items[j].Name)
slices.SortFunc(resp.Items, func(a, b plugin.Plugin) int {
return sortorder.NaturalCompare(a.Name, b.Name)
})

format := options.format
Expand Down
10 changes: 7 additions & 3 deletions cli/command/secret/ls.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
// FIXME(thaJeztah): remove once we are a module; the go:build directive prevents go from downgrading language version to go1.16:
//go:build go1.26

package secret

import (
"context"
"sort"
"slices"

"github.com/docker/cli/cli"
"github.com/docker/cli/cli/command"
"github.com/docker/cli/cli/command/formatter"
flagsHelper "github.com/docker/cli/cli/flags"
"github.com/docker/cli/opts"
"github.com/fvbommel/sortorder"
"github.com/moby/moby/api/types/swarm"
"github.com/moby/moby/client"
"github.com/spf13/cobra"
)
Expand Down Expand Up @@ -59,8 +63,8 @@ func runSecretList(ctx context.Context, dockerCLI command.Cli, options listOptio
}
}

sort.Slice(res.Items, func(i, j int) bool {
return sortorder.NaturalLess(res.Items[i].Spec.Name, res.Items[j].Spec.Name)
slices.SortFunc(res.Items, func(a, b swarm.Secret) int {
return sortorder.NaturalCompare(a.Spec.Name, b.Spec.Name)
})

secretCtx := formatter.Context{
Expand Down
5 changes: 2 additions & 3 deletions cli/command/service/formatter.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"errors"
"fmt"
"slices"
"sort"
"strconv"
"strings"
"time"
Expand Down Expand Up @@ -620,8 +619,8 @@ func NewListFormat(source string, quiet bool) formatter.Format {
// ListFormatWrite writes the context
func ListFormatWrite(ctx formatter.Context, services client.ServiceListResult) error {
render := func(format func(subContext formatter.SubContext) error) error {
sort.Slice(services.Items, func(i, j int) bool {
return sortorder.NaturalLess(services.Items[i].Spec.Name, services.Items[j].Spec.Name)
slices.SortFunc(services.Items, func(a, b swarm.Service) int {
return sortorder.NaturalCompare(a.Spec.Name, b.Spec.Name)
})
for _, service := range services.Items {
serviceCtx := &serviceContext{service: service}
Expand Down
9 changes: 6 additions & 3 deletions cli/command/stack/list.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
// FIXME(thaJeztah): remove once we are a module; the go:build directive prevents go from downgrading language version to go1.16:
//go:build go1.26

package stack

import (
"context"
"sort"
"slices"

"github.com/docker/cli/cli"
"github.com/docker/cli/cli/command"
Expand Down Expand Up @@ -52,8 +55,8 @@ func runList(ctx context.Context, dockerCLI command.Cli, opts listOptions) error
Output: dockerCLI.Out(),
Format: format,
}
sort.Slice(stacks, func(i, j int) bool {
return sortorder.NaturalLess(stacks[i].Name, stacks[j].Name)
slices.SortFunc(stacks, func(a, b stackSummary) int {
return sortorder.NaturalCompare(a.Name, b.Name)
})
return stackWrite(stackCtx, stacks)
}
10 changes: 7 additions & 3 deletions cli/command/stack/services.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
// FIXME(thaJeztah): remove once we are a module; the go:build directive prevents go from downgrading language version to go1.16:
//go:build go1.26

package stack

import (
"context"
"fmt"
"sort"
"slices"

"github.com/docker/cli/cli"
"github.com/docker/cli/cli/command"
Expand All @@ -12,6 +15,7 @@ import (
flagsHelper "github.com/docker/cli/cli/flags"
cliopts "github.com/docker/cli/opts"
"github.com/fvbommel/sortorder"
"github.com/moby/moby/api/types/swarm"
"github.com/moby/moby/client"
"github.com/spf13/cobra"
)
Expand Down Expand Up @@ -68,8 +72,8 @@ func formatWrite(dockerCLI command.Cli, services client.ServiceListResult, opts
_, _ = fmt.Fprintln(dockerCLI.Err(), "Nothing found in stack:", opts.namespace)
return nil
}
sort.Slice(services.Items, func(i, j int) bool {
return sortorder.NaturalLess(services.Items[i].Spec.Name, services.Items[j].Spec.Name)
slices.SortFunc(services.Items, func(a, b swarm.Service) int {
return sortorder.NaturalCompare(a.Spec.Name, b.Spec.Name)
})

f := opts.format
Expand Down
6 changes: 2 additions & 4 deletions cli/command/system/prune.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"context"
"errors"
"fmt"
"sort"
"slices"
"text/template"

"github.com/containerd/errdefs"
Expand Down Expand Up @@ -172,9 +172,7 @@ func dryRun(ctx context.Context, dockerCli command.Cli, options pruneOptions) (s
filters = append(filters, name+"="+v)
}
}
sort.Slice(filters, func(i, j int) bool {
return sortorder.NaturalLess(filters[i], filters[j])
})
slices.SortFunc(filters, sortorder.NaturalCompare)
}

var buffer bytes.Buffer
Expand Down
Loading
Loading