Merge pull request #1166 from adshmh/add-sort-to-plugin-list

Sort plugin names in a natural order
This commit is contained in:
Brian Goff 2018-07-05 16:34:25 -07:00 committed by GitHub
commit 8160759013
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 33 additions and 0 deletions

View File

@ -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 {

View File

@ -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 {

View File

@ -0,0 +1,3 @@
plugin-1-foo
plugin-2-foo
plugin-10-foo