Skip to content

Commit

Permalink
Add optional bool to generate legacy compatible output (default is fa…
Browse files Browse the repository at this point in the history
…lse)
  • Loading branch information
HikariKnight authored and HikariKnight committed Mar 7, 2023
1 parent d066799 commit fcaad8e
Showing 1 changed file with 33 additions and 23 deletions.
56 changes: 33 additions & 23 deletions lib/genoutput.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,37 +7,47 @@ import (
"github.com/jaypipes/ghw/pkg/pci"
)

func GenDeviceLine(group int, device *pci.Device) string {
func GenDeviceLine(group int, device *pci.Device, legacyoutput ...bool) string {
var line string
pciaddrclean := regexp.MustCompile(`^\d+:`)

// If we want legacy output (to be output compatible with the bash version)
var iommu_group string
if len(legacyoutput) > 0 {
// Do not pad the group number
iommu_group = fmt.Sprintf("%d", group)
} else {
// Else we pad the group number to make it sortable
iommu_group = fmt.Sprintf("% 3d", group)
}

// If the device has no revision, ommit the (rev ID), in both cases we generate the line with device info
if device.Revision != "0x00" {
line = fmt.Sprintf("IOMMU Group % 3d: %s %s [%s%s]: %s %s [%s:%s] (rev %s)\n",
group,
pciaddrclean.ReplaceAllString(device.Address, ""),
device.Subclass.Name,
device.Class.ID,
device.Subclass.ID,
device.Vendor.Name,
device.Product.Name,
device.Vendor.ID,
device.Product.ID,
device.Revision[len(device.Revision)-2:],
line = fmt.Sprintf("IOMMU Group %s: %s %s [%s%s]: %s %s [%s:%s] (rev %s)\n",
iommu_group,
pciaddrclean.ReplaceAllString(device.Address, ""),
device.Subclass.Name,
device.Class.ID,
device.Subclass.ID,
device.Vendor.Name,
device.Product.Name,
device.Vendor.ID,
device.Product.ID,
device.Revision[len(device.Revision)-2:],
)
} else {
line = fmt.Sprintf("IOMMU Group % 3d: %s %s [%s%s]: %s %s [%s:%s]\n",
group,
pciaddrclean.ReplaceAllString(device.Address, ""),
device.Subclass.Name,
device.Class.ID,
device.Subclass.ID,
device.Vendor.Name,
device.Product.Name,
device.Vendor.ID,
device.Product.ID,
line = fmt.Sprintf("IOMMU Group %s: %s %s [%s%s]: %s %s [%s:%s]\n",
iommu_group,
pciaddrclean.ReplaceAllString(device.Address, ""),
device.Subclass.Name,
device.Class.ID,
device.Subclass.ID,
device.Vendor.Name,
device.Product.Name,
device.Vendor.ID,
device.Product.ID,
)
}

return line
}
}

0 comments on commit fcaad8e

Please sign in to comment.