refactored all commands under cli/command/ to use sort.Slice instead of declaring custom types for sorting

Signed-off-by: Arash Deshmeh <adeshmeh@ca.ibm.com>
This commit is contained in:
Arash Deshmeh
2018-07-06 15:49:10 -04:00
parent 2634562119
commit ceed42217d
10 changed files with 57 additions and 116 deletions

View File

@ -8,18 +8,9 @@ import (
"github.com/docker/cli/cli/command"
"github.com/docker/cli/cli/command/formatter"
"github.com/docker/cli/opts"
"github.com/docker/docker/api/types"
"github.com/spf13/cobra"
)
type byVolumeName []*types.Volume
func (r byVolumeName) Len() int { return len(r) }
func (r byVolumeName) Swap(i, j int) { r[i], r[j] = r[j], r[i] }
func (r byVolumeName) Less(i, j int) bool {
return r[i].Name < r[j].Name
}
type listOptions struct {
quiet bool
format string
@ -63,7 +54,9 @@ func runList(dockerCli command.Cli, options listOptions) error {
}
}
sort.Sort(byVolumeName(volumes.Volumes))
sort.Slice(volumes.Volumes, func(i, j int) bool {
return volumes.Volumes[i].Name < volumes.Volumes[j].Name
})
volumeCtx := formatter.Context{
Output: dockerCli.Out(),