From d3c85f97c2ae96d55d2646e17763eecc07d88815 Mon Sep 17 00:00:00 2001 From: Abhilash Gnan Date: Tue, 2 Apr 2019 21:14:13 +0200 Subject: [PATCH] fix sort list with options bug Signed-off-by: Abhilash Gnan --- cmd/helm/list.go | 2 +- pkg/action/list.go | 27 ++++++++++++++++++++++----- 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/cmd/helm/list.go b/cmd/helm/list.go index 7ed340482..cd56cff79 100644 --- a/cmd/helm/list.go +++ b/cmd/helm/list.go @@ -86,7 +86,7 @@ func newListCmd(cfg *action.Configuration, out io.Writer) *cobra.Command { f := cmd.Flags() f.BoolVarP(&client.Short, "short", "q", false, "output short (quiet) listing format") f.BoolVarP(&client.ByDate, "date", "d", false, "sort by release date") - f.BoolVarP(&client.SortDesc, "reverse", "r", false, "reverse the sort order") + f.BoolVarP(&client.SortReverse, "reverse", "r", false, "reverse the sort order") f.BoolVarP(&client.All, "all", "a", false, "show all releases, not just the ones marked deployed") f.BoolVar(&client.Uninstalled, "uninstalled", false, "show uninstalled releases") f.BoolVar(&client.Superseded, "superseded", false, "show superseded releases") diff --git a/pkg/action/list.go b/pkg/action/list.go index 063b4d28e..9e2e5258a 100644 --- a/pkg/action/list.go +++ b/pkg/action/list.go @@ -87,8 +87,10 @@ const ListAll = ListDeployed | ListUninstalled | ListUninstalling | ListPendingI type Sorter uint const ( - // ByDate sorts by date - ByDate Sorter = iota + // ByDateAsc sorts by ascending dates (oldest updated release first) + ByDateAsc Sorter = iota + // ByDateDesc sorts by descending dates (latest updated release first) + ByDateDesc // ByNameAsc sorts by ascending lexicographic order ByNameAsc // ByNameDesc sorts by descending lexicographic order @@ -109,6 +111,9 @@ type List struct { // // see pkg/releaseutil for several useful sorters Sort Sorter + // Overrides the default lexicographic sorting + ByDate bool + SortReverse bool // StateMask accepts a bitmask of states for items to show. // The default is ListDeployed StateMask ListStates @@ -119,8 +124,6 @@ type List struct { // Filter is a filter that is applied to the results Filter string Short bool - ByDate bool - SortDesc bool Uninstalled bool Superseded bool Uninstalling bool @@ -194,9 +197,23 @@ func (l *List) Run() ([]*release.Release, error) { // sort is an in-place sort where order is based on the value of a.Sort func (l *List) sort(rels []*release.Release) { + l.Sort = ByNameAsc + if l.SortReverse { + l.Sort = ByNameDesc + } + + if l.ByDate { + l.Sort = ByDateDesc + if l.SortReverse { + l.Sort = ByDateAsc + } + } + switch l.Sort { - case ByDate: + case ByDateDesc: releaseutil.SortByDate(rels) + case ByDateAsc: + releaseutil.Reverse(rels, releaseutil.SortByDate) case ByNameDesc: releaseutil.Reverse(rels, releaseutil.SortByName) default: