Skip to content

Commit

Permalink
list/firmware: fix filtering by component type
Browse files Browse the repository at this point in the history
  • Loading branch information
joelrebel committed Apr 10, 2024
1 parent 46f6a05 commit 9d20393
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 12 deletions.
19 changes: 8 additions & 11 deletions cmd/list/firmware.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import (
)

type listFirmwareFlags struct {
server string // server UUID
vendor string
model string
component string
Expand Down Expand Up @@ -65,23 +64,22 @@ var listFirmware = &cobra.Command{
log.Fatal("fleetdb API client returned error: ", err)
}

if output == mctl.OutputTypeJSON.String() {
printJSON(firmware)
os.Exit(0)
}

// the built in filter only filters out vendor, model, and version, will have to filter out the other columns manually
if flagsDefinedListFirmware.server != "" || flagsDefinedListFirmware.component != "" {
if flagsDefinedListFirmware.component != "" {
filteredFirmware := make([]fleetdbapi.ComponentFirmwareVersion, 0)
for _, f := range firmware {
if (flagsDefinedListFirmware.server == "" || f.UUID.String() == flagsDefinedListFirmware.server) &&
(flagsDefinedListFirmware.component == "" || f.Component == flagsDefinedListFirmware.component) {
if f.Component == flagsDefinedListFirmware.component {
filteredFirmware = append(filteredFirmware, f)
}
}
firmware = filteredFirmware
}

if output == mctl.OutputTypeJSON.String() {
printJSON(firmware)
os.Exit(0)
}

table := tablewriter.NewWriter(os.Stdout)
table.SetHeader([]string{"UUID", "Vendor", "Model", "Component", "Version"})
for _, f := range firmware {
Expand All @@ -94,10 +92,9 @@ var listFirmware = &cobra.Command{
func init() {
flagsDefinedListFirmware = &listFirmwareFlags{limit: 10}

mctl.AddServerFlag(listFirmware, &flagsDefinedListFirmware.server)
mctl.AddVendorFlag(listFirmware, &flagsDefinedListFirmware.vendor)
mctl.AddModelFlag(listFirmware, &flagsDefinedListFirmware.model)
mctl.AddComponentTypeFlag(listFirmware, &flagsListComponent.slug)
mctl.AddComponentTypeFlag(listFirmware, &flagsDefinedListFirmware.component)
mctl.AddFirmwareVersionFlag(listFirmware, &flagsDefinedListFirmware.version)
mctl.AddPageLimitFlag(listFirmware, &flagsDefinedListFirmware.limit)
mctl.AddPageFlag(listFirmware, &flagsDefinedListFirmware.page)
Expand Down
1 change: 0 additions & 1 deletion docs/mctl_list_firmware.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ mctl list firmware [flags]
--limit int limit results returned. Max value is 1000 (hard limit set in fleetdb). To list more than 1000, you must query each page (with '--page') individually (default 10)
-m, --model string filter by model
--page int limit results to page (for use with --limit)
-s, --server string ID of the server
-v, --vendor string filter by vendor
```

Expand Down

0 comments on commit 9d20393

Please sign in to comment.