Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sort plugin names in a natural order #1166

Merged
merged 1 commit into from
Jul 5, 2018
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
6 changes: 6 additions & 0 deletions cli/command/plugin/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down
24 changes: 24 additions & 0 deletions cli/command/plugin/list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
3 changes: 3 additions & 0 deletions cli/command/plugin/testdata/plugin-list-sort.golden
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
plugin-1-foo
plugin-2-foo
plugin-10-foo