mirror of https://github.com/docker/cli.git
Merge pull request #1166 from adshmh/add-sort-to-plugin-list
Sort plugin names in a natural order
This commit is contained in:
commit
8160759013
|
@ -2,12 +2,14 @@ package plugin
|
|||
|
||||
import (
|
||||
"context"
|
||||
"sort"
|
||||
|
||||
"github.com/docker/cli/cli"
|
||||
"github.com/docker/cli/cli/command"
|
||||
"github.com/docker/cli/cli/command/formatter"
|
||||
"github.com/docker/cli/opts"
|
||||
"github.com/spf13/cobra"
|
||||
"vbom.ml/util/sortorder"
|
||||
)
|
||||
|
||||
type listOptions struct {
|
||||
|
@ -46,6 +48,10 @@ func runList(dockerCli command.Cli, options listOptions) error {
|
|||
return err
|
||||
}
|
||||
|
||||
sort.Slice(plugins, func(i, j int) bool {
|
||||
return sortorder.NaturalLess(plugins[i].Name, plugins[j].Name)
|
||||
})
|
||||
|
||||
format := options.format
|
||||
if len(format) == 0 {
|
||||
if len(dockerCli.ConfigFile().PluginsFormat) > 0 && !options.quiet {
|
||||
|
|
|
@ -135,6 +135,30 @@ func TestList(t *testing.T) {
|
|||
golden: "plugin-list-with-format.golden",
|
||||
listFunc: singlePluginListFunc,
|
||||
},
|
||||
{
|
||||
description: "list output is sorted based on plugin name",
|
||||
args: []string{},
|
||||
flags: map[string]string{
|
||||
"format": "{{ .Name }}",
|
||||
},
|
||||
golden: "plugin-list-sort.golden",
|
||||
listFunc: func(filter filters.Args) (types.PluginsListResponse, error) {
|
||||
return types.PluginsListResponse{
|
||||
{
|
||||
ID: "id-1",
|
||||
Name: "plugin-1-foo",
|
||||
},
|
||||
{
|
||||
ID: "id-2",
|
||||
Name: "plugin-10-foo",
|
||||
},
|
||||
{
|
||||
ID: "id-3",
|
||||
Name: "plugin-2-foo",
|
||||
},
|
||||
}, nil
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range testCases {
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
plugin-1-foo
|
||||
plugin-2-foo
|
||||
plugin-10-foo
|
Loading…
Reference in New Issue