Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions cmd/admin/v2/component.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
adminv2 "github.com/metal-stack/api/go/metalstack/admin/v2"
apiv2 "github.com/metal-stack/api/go/metalstack/api/v2"
"github.com/metal-stack/cli/cmd/config"
"github.com/metal-stack/cli/cmd/sorters"
"github.com/metal-stack/metal-lib/pkg/genericcli"
"github.com/metal-stack/metal-lib/pkg/genericcli/printers"
"github.com/metal-stack/metal-lib/pkg/pointer"
Expand All @@ -32,6 +33,7 @@ func newComponentCmd(c *config.Config) *cobra.Command {
Description: "list status of components, e.g. microservices connected to the metal-apiserver",
DescribePrinter: func() printers.Printer { return c.DescribePrinter },
ListPrinter: func() printers.Printer { return c.ListPrinter },
Sorter: sorters.ComponentSorter(),
OnlyCmds: genericcli.OnlyCmds(genericcli.DescribeCmd, genericcli.ListCmd, genericcli.DeleteCmd),
ListCmdMutateFn: func(cmd *cobra.Command) {
cmd.Flags().String("uuid", "", "lists only component with this uuid")
Expand Down
23 changes: 23 additions & 0 deletions cmd/sorters/component.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package sorters

import (
apiv2 "github.com/metal-stack/api/go/metalstack/api/v2"
"github.com/metal-stack/metal-lib/pkg/multisort"
)

func ComponentSorter() *multisort.Sorter[*apiv2.Component] {
return multisort.New(multisort.FieldMap[*apiv2.Component]{
"type": func(a, b *apiv2.Component, descending bool) multisort.CompareResult {
return multisort.Compare(a.Type, b.Type, descending)
},
"identifier": func(a, b *apiv2.Component, descending bool) multisort.CompareResult {
return multisort.Compare(a.Identifier, b.Identifier, descending)
},
"started": func(a, b *apiv2.Component, descending bool) multisort.CompareResult {
Comment thread
Gerrit91 marked this conversation as resolved.
return multisort.Compare(a.StartedAt.AsTime().String(), b.StartedAt.AsTime().String(), descending)
},
"expiration": func(a, b *apiv2.Component, descending bool) multisort.CompareResult {
return multisort.Compare(a.Token.Expires.String(), b.Token.Expires.String(), descending)
},
}, multisort.Keys{{ID: "type", Descending: true}, {ID: "identifier", Descending: true}})
}
1 change: 1 addition & 0 deletions docs/admin/metalctlv2_admin_component_list.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ metalctlv2 admin component list [flags]
```
-h, --help help for list
--identifier string lists only component with this identifier
--sort-by strings sort by (comma separated) column(s), sort direction can be changed by appending :asc or :desc behind the column identifier. possible values: identifier|started|type
--type string lists only component of this type
--uuid string lists only component with this uuid
```
Expand Down