fix sort list with options bug

Signed-off-by: Abhilash Gnan <abhilashgnan@gmail.com>
pull/5539/head
Abhilash Gnan 6 years ago
parent d4323c1da8
commit d3c85f97c2

@ -86,7 +86,7 @@ func newListCmd(cfg *action.Configuration, out io.Writer) *cobra.Command {
f := cmd.Flags() f := cmd.Flags()
f.BoolVarP(&client.Short, "short", "q", false, "output short (quiet) listing format") 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.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.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.Uninstalled, "uninstalled", false, "show uninstalled releases")
f.BoolVar(&client.Superseded, "superseded", false, "show superseded releases") f.BoolVar(&client.Superseded, "superseded", false, "show superseded releases")

@ -87,8 +87,10 @@ const ListAll = ListDeployed | ListUninstalled | ListUninstalling | ListPendingI
type Sorter uint type Sorter uint
const ( const (
// ByDate sorts by date // ByDateAsc sorts by ascending dates (oldest updated release first)
ByDate Sorter = iota ByDateAsc Sorter = iota
// ByDateDesc sorts by descending dates (latest updated release first)
ByDateDesc
// ByNameAsc sorts by ascending lexicographic order // ByNameAsc sorts by ascending lexicographic order
ByNameAsc ByNameAsc
// ByNameDesc sorts by descending lexicographic order // ByNameDesc sorts by descending lexicographic order
@ -109,6 +111,9 @@ type List struct {
// //
// see pkg/releaseutil for several useful sorters // see pkg/releaseutil for several useful sorters
Sort Sorter Sort Sorter
// Overrides the default lexicographic sorting
ByDate bool
SortReverse bool
// StateMask accepts a bitmask of states for items to show. // StateMask accepts a bitmask of states for items to show.
// The default is ListDeployed // The default is ListDeployed
StateMask ListStates StateMask ListStates
@ -119,8 +124,6 @@ type List struct {
// Filter is a filter that is applied to the results // Filter is a filter that is applied to the results
Filter string Filter string
Short bool Short bool
ByDate bool
SortDesc bool
Uninstalled bool Uninstalled bool
Superseded bool Superseded bool
Uninstalling 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 // sort is an in-place sort where order is based on the value of a.Sort
func (l *List) sort(rels []*release.Release) { 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 { switch l.Sort {
case ByDate: case ByDateDesc:
releaseutil.SortByDate(rels) releaseutil.SortByDate(rels)
case ByDateAsc:
releaseutil.Reverse(rels, releaseutil.SortByDate)
case ByNameDesc: case ByNameDesc:
releaseutil.Reverse(rels, releaseutil.SortByName) releaseutil.Reverse(rels, releaseutil.SortByName)
default: default:

Loading…
Cancel
Save