diff --git a/cli/command/volume/list.go b/cli/command/volume/list.go index 1fb446ffc7..f9afef8bf6 100644 --- a/cli/command/volume/list.go +++ b/cli/command/volume/list.go @@ -9,6 +9,7 @@ import ( "github.com/docker/cli/cli/command/formatter" "github.com/docker/cli/opts" "github.com/spf13/cobra" + "vbom.ml/util/sortorder" ) type listOptions struct { @@ -55,7 +56,7 @@ func runList(dockerCli command.Cli, options listOptions) error { } sort.Slice(volumes.Volumes, func(i, j int) bool { - return volumes.Volumes[i].Name < volumes.Volumes[j].Name + return sortorder.NaturalLess(volumes.Volumes[i].Name, volumes.Volumes[j].Name) }) volumeCtx := formatter.Context{ diff --git a/cli/command/volume/list_test.go b/cli/command/volume/list_test.go index 62d7d95664..9159eb89ef 100644 --- a/cli/command/volume/list_test.go +++ b/cli/command/volume/list_test.go @@ -109,3 +109,21 @@ func TestVolumeListWithFormat(t *testing.T) { assert.NilError(t, cmd.Execute()) golden.Assert(t, cli.OutBuffer().String(), "volume-list-with-format.golden") } + +func TestVolumeListSortOrder(t *testing.T) { + cli := test.NewFakeCli(&fakeClient{ + volumeListFunc: func(filter filters.Args) (volumetypes.VolumeListOKBody, error) { + return volumetypes.VolumeListOKBody{ + Volumes: []*types.Volume{ + Volume(VolumeName("volume-2-foo")), + Volume(VolumeName("volume-10-foo")), + Volume(VolumeName("volume-1-foo")), + }, + }, nil + }, + }) + cmd := newListCommand(cli) + cmd.Flags().Set("format", "{{ .Name }}") + assert.NilError(t, cmd.Execute()) + golden.Assert(t, cli.OutBuffer().String(), "volume-list-sort.golden") +} diff --git a/cli/command/volume/testdata/volume-list-sort.golden b/cli/command/volume/testdata/volume-list-sort.golden new file mode 100644 index 0000000000..03f133cc7d --- /dev/null +++ b/cli/command/volume/testdata/volume-list-sort.golden @@ -0,0 +1,3 @@ +volume-1-foo +volume-2-foo +volume-10-foo