add params required for sort byNamespace

Signed-off-by: Abhilash Gnan <abhilashgnan@gmail.com>
pull/5704/head
Abhilash Gnan 6 years ago
parent ffc71f9b7b
commit afb9ce6a10

@ -125,6 +125,7 @@ message ListSort{
NAME = 1;
LAST_RELEASED = 2;
CHART_NAME = 3;
NAMESPACE = 4;
}
// SortOrder defines sort orders to augment sorting operations.

@ -79,6 +79,7 @@ type listCmd struct {
colWidth uint
output string
byChartName bool
byNamespace bool
}
type listResult struct {
@ -136,6 +137,7 @@ func newListCmd(client helm.Interface, out io.Writer) *cobra.Command {
f.UintVar(&list.colWidth, "col-width", 60, "specifies the max column width of output")
f.StringVar(&list.output, "output", "", "output the specified format (json or yaml)")
f.BoolVarP(&list.byChartName, "chart-name", "c", false, "sort by chart name")
f.BoolVarP(&list.byNamespace, "namespace-name", "n", false, "sort by namespace name")
// TODO: Do we want this as a feature of 'helm list'?
//f.BoolVar(&list.superseded, "history", true, "show historical releases")
@ -154,6 +156,9 @@ func (l *listCmd) run() error {
if l.byChartName {
sortBy = services.ListSort_CHART_NAME
}
if l.byNamespace {
sortBy = services.ListSort_NAMESPACE
}
sortOrder := services.ListSort_ASC
if l.sortDesc {

@ -98,3 +98,15 @@ func SortByChartName(list []*rspb.Release) {
}
sort.Sort(s)
}
// SortByNamespace sorts the list of releases by a
// release's namespace name in lexicographical order.
func SortByNamespace(list []*rspb.Release) {
s := &sorter{list: list}
s.less = func(i, j int) bool {
ni := s.list[i].Namespace
nj := s.list[j].Namespace
return ni < nj
}
sort.Sort(s)
}

@ -68,6 +68,8 @@ func (s *ReleaseServer) ListReleases(req *services.ListReleasesRequest, stream s
relutil.SortByDate(rels)
case services.ListSort_CHART_NAME:
relutil.SortByChartName(rels)
case services.ListSort_NAMESPACE:
relutil.SortByNamespace(rels)
}
if req.SortOrder == services.ListSort_DESC {

Loading…
Cancel
Save