Skip to content

Commit

Permalink
Add option to list all fw-sets (#24)
Browse files Browse the repository at this point in the history
By default mctl list firmware-sets will list only firmware sets containing labels for vendor, model and latest=true.

This change adds a --all option to list all sets without any filters
  • Loading branch information
diogomatsubara authored Aug 1, 2023
1 parent 5b4b154 commit 1fc211b
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions cmd/list/firmware_set.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,14 @@ import (
"github.com/metal-toolbox/mctl/pkg/model"
"github.com/olekukonko/tablewriter"
"github.com/spf13/cobra"

serverservice "go.hollow.sh/serverservice/pkg/api/v1"
)

type listFirmwareSetFlags struct {
vendor string
model string
vendor string
model string
listAll bool
}

var (
Expand All @@ -33,9 +36,17 @@ var listFirmwareSet = &cobra.Command{
log.Fatal(err)
}

fwSet, err := mctl.FirmwareSetByVendorModel(cmd.Context(), flagsDefinedListFwSet.vendor, flagsDefinedListFwSet.model, client)
if err != nil {
log.Fatal(err)
var fwSet []serverservice.ComponentFirmwareSet
if flagsDefinedListFwSet.listAll {
fwSet, _, err = client.ListServerComponentFirmwareSet(cmd.Context(), &serverservice.ComponentFirmwareSetListParams{})
if err != nil {
log.Fatal(err)
}
} else {
fwSet, err = mctl.FirmwareSetByVendorModel(cmd.Context(), flagsDefinedListFwSet.vendor, flagsDefinedListFwSet.model, client)
if err != nil {
log.Fatal(err)
}
}

if outputJSON {
Expand Down Expand Up @@ -69,4 +80,5 @@ func init() {

listFirmwareSet.PersistentFlags().StringVar(&flagsDefinedListFwSet.vendor, "vendor", "", "filter by server vendor")
listFirmwareSet.PersistentFlags().StringVar(&flagsDefinedListFwSet.model, "model", "", "filter by server model")
listFirmwareSet.PersistentFlags().BoolVar(&flagsDefinedListFwSet.listAll, "all", false, "show all firmware sets. By default results are filtered on having labels for vendor, model and latest=true")
}

0 comments on commit 1fc211b

Please sign in to comment.