diff --git a/pkg/list.go b/pkg/list.go index a72748d..43e1f23 100644 --- a/pkg/list.go +++ b/pkg/list.go @@ -72,14 +72,31 @@ func ListDrives(cc *crawler.CrawlerConfig) ([]*redfish.Drive, error) { return foundDrives, nil } -func PrintDrives(drives []*redfish.Drive) { - for i, drive := range drives { - fmt.Printf("Drive %d\n", i) - fmt.Printf("\tManufacturer: %s\n", drive.Manufacturer) - fmt.Printf("\tModel: %s\n", drive.Model) - fmt.Printf("\tSize: %d GiB\n", (drive.CapacityBytes / 1024 / 1024 / 1024)) - fmt.Printf("\tSerial number: %s\n", drive.SerialNumber) - fmt.Printf("\tPart number: %s\n", drive.PartNumber) - fmt.Printf("\tLocation: %s %d\n", drive.PhysicalLocation.PartLocation.LocationType, drive.PhysicalLocation.PartLocation.LocationOrdinalValue) +func PrintDrives(drives []*redfish.Drive, format string) { + switch format { + case "json": + util.PrintJSON(drives) + case "yaml": + util.PrintYAML(drives) + case "list": + for i, drive := range drives { + fmt.Printf(` +Drive %d +\tManufacturuer: %s +\tModel: %s +\tSize: %d GiB +\tSerial Number: %s +\tPart Number: %s +\tLocation: %s,%s +`, i, + drive.Manufacturer, + drive.Model, + (drive.CapacityBytes / 1024 / 1024 / 1024), + drive.SerialNumber, + drive.PartNumber, + drive.PhysicalLocation.PartLocation.LocationType, + drive.PhysicalLocation.PartLocation.LocationOrdinalValue, + ) + } } }