diff --git a/cmd/ghwc/commands/accelerator.go b/cmd/ghwc/commands/accelerator.go index 89db4f22..cb969cb7 100644 --- a/cmd/ghwc/commands/accelerator.go +++ b/cmd/ghwc/commands/accelerator.go @@ -35,9 +35,9 @@ func showAccelerator(cmd *cobra.Command, args []string) error { fmt.Printf(" %v\n", card) } case outputFormatJSON: - fmt.Printf("%s\n", accel.JSONString(pretty)) + fmt.Printf("%s\n", JSONString(accel, pretty)) case outputFormatYAML: - fmt.Printf("%s", accel.YAMLString()) + fmt.Printf("%s", YAMLString(accel)) } return nil } diff --git a/cmd/ghwc/commands/baseboard.go b/cmd/ghwc/commands/baseboard.go index 4cee0bc7..37b24c60 100644 --- a/cmd/ghwc/commands/baseboard.go +++ b/cmd/ghwc/commands/baseboard.go @@ -27,14 +27,7 @@ func showBaseboard(cmd *cobra.Command, args []string) error { return fmt.Errorf("error getting baseboard info: %w", err) } - switch outputFormat { - case outputFormatHuman: - fmt.Printf("%v\n", baseboard) - case outputFormatJSON: - fmt.Printf("%s\n", baseboard.JSONString(pretty)) - case outputFormatYAML: - fmt.Printf("%s", baseboard.YAMLString()) - } + printInfo(baseboard) return nil } diff --git a/cmd/ghwc/commands/bios.go b/cmd/ghwc/commands/bios.go index c178b6ad..6b818dfc 100644 --- a/cmd/ghwc/commands/bios.go +++ b/cmd/ghwc/commands/bios.go @@ -27,14 +27,7 @@ func showBIOS(cmd *cobra.Command, args []string) error { return fmt.Errorf("error getting BIOS info: %w", err) } - switch outputFormat { - case outputFormatHuman: - fmt.Printf("%v\n", bios) - case outputFormatJSON: - fmt.Printf("%s\n", bios.JSONString(pretty)) - case outputFormatYAML: - fmt.Printf("%s", bios.YAMLString()) - } + printInfo(bios) return nil } diff --git a/cmd/ghwc/commands/block.go b/cmd/ghwc/commands/block.go index 208a905d..9d10eb4a 100644 --- a/cmd/ghwc/commands/block.go +++ b/cmd/ghwc/commands/block.go @@ -38,9 +38,9 @@ func showBlock(cmd *cobra.Command, args []string) error { } } case outputFormatJSON: - fmt.Printf("%s\n", block.JSONString(pretty)) + fmt.Printf("%s\n", JSONString(block, pretty)) case outputFormatYAML: - fmt.Printf("%s", block.YAMLString()) + fmt.Printf("%s", YAMLString(block)) } return nil } diff --git a/cmd/ghwc/commands/chassis.go b/cmd/ghwc/commands/chassis.go index e76331e0..10087fc5 100644 --- a/cmd/ghwc/commands/chassis.go +++ b/cmd/ghwc/commands/chassis.go @@ -27,14 +27,7 @@ func showChassis(cmd *cobra.Command, args []string) error { return fmt.Errorf("error getting chassis info: %w", err) } - switch outputFormat { - case outputFormatHuman: - fmt.Printf("%v\n", chassis) - case outputFormatJSON: - fmt.Printf("%s\n", chassis.JSONString(pretty)) - case outputFormatYAML: - fmt.Printf("%s", chassis.YAMLString()) - } + printInfo(chassis) return nil } diff --git a/cmd/ghwc/commands/cpu.go b/cmd/ghwc/commands/cpu.go index 259006bf..761100f1 100644 --- a/cmd/ghwc/commands/cpu.go +++ b/cmd/ghwc/commands/cpu.go @@ -58,9 +58,9 @@ func showCPU(cmd *cobra.Command, args []string) error { } } case outputFormatJSON: - fmt.Printf("%s\n", cpu.JSONString(pretty)) + fmt.Printf("%s\n", JSONString(cpu, pretty)) case outputFormatYAML: - fmt.Printf("%s", cpu.YAMLString()) + fmt.Printf("%s", YAMLString(cpu)) } return nil } diff --git a/cmd/ghwc/commands/gpu.go b/cmd/ghwc/commands/gpu.go index 869d93e6..0f596166 100644 --- a/cmd/ghwc/commands/gpu.go +++ b/cmd/ghwc/commands/gpu.go @@ -35,9 +35,9 @@ func showGPU(cmd *cobra.Command, args []string) error { fmt.Printf(" %v\n", card) } case outputFormatJSON: - fmt.Printf("%s\n", gpu.JSONString(pretty)) + fmt.Printf("%s\n", JSONString(gpu, pretty)) case outputFormatYAML: - fmt.Printf("%s", gpu.YAMLString()) + fmt.Printf("%s", YAMLString(gpu)) } return nil } diff --git a/cmd/ghwc/commands/marshal.go b/cmd/ghwc/commands/marshal.go new file mode 100644 index 00000000..c90701a4 --- /dev/null +++ b/cmd/ghwc/commands/marshal.go @@ -0,0 +1,50 @@ +// +// Use and distribution licensed under the Apache license version 2. +// +// See the COPYING file in the root project directory for full text. +// + +package commands + +import ( + "encoding/json" + + yaml "gopkg.in/yaml.v3" +) + +// YAMLString returns a string after marshalling the supplied parameter into YAML. +func YAMLString(p interface{}) string { + b, err := json.Marshal(p) + if err != nil { + return "" + } + + var jsonObj interface{} + if err := yaml.Unmarshal(b, &jsonObj); err != nil { + return "" + } + + yb, err := yaml.Marshal(jsonObj) + if err != nil { + return "" + } + + return string(yb) +} + +// JSONString returns a string after marshalling the supplied parameter into +// JSON. Accepts an optional argument to trigger pretty/indented formatting of +// the JSON string. +func JSONString(p interface{}, indent bool) string { + var b []byte + var err error + if !indent { + b, err = json.Marshal(p) + } else { + b, err = json.MarshalIndent(&p, "", " ") + } + if err != nil { + return "" + } + return string(b) +} diff --git a/cmd/ghwc/commands/net.go b/cmd/ghwc/commands/net.go index 843cba99..016c3304 100644 --- a/cmd/ghwc/commands/net.go +++ b/cmd/ghwc/commands/net.go @@ -48,9 +48,9 @@ func showNetwork(cmd *cobra.Command, args []string) error { } } case outputFormatJSON: - fmt.Printf("%s\n", net.JSONString(pretty)) + fmt.Printf("%s\n", JSONString(net, pretty)) case outputFormatYAML: - fmt.Printf("%s", net.YAMLString()) + fmt.Printf("%s", YAMLString(net)) } return nil } diff --git a/cmd/ghwc/commands/print_util.go b/cmd/ghwc/commands/print_util.go index 23bbd7d2..02ab709d 100644 --- a/cmd/ghwc/commands/print_util.go +++ b/cmd/ghwc/commands/print_util.go @@ -6,21 +6,16 @@ package commands -import "fmt" +import ( + "fmt" +) -type formattable interface { - String() string - JSONString(bool) string - YAMLString() string -} - -func printInfo(f formattable) { +func printInfo(f interface{}) { switch outputFormat { - case outputFormatHuman: - fmt.Printf("%s\n", f) case outputFormatJSON: - fmt.Printf("%s\n", f.JSONString(pretty)) + f = JSONString(f, pretty) case outputFormatYAML: - fmt.Printf("%s", f.YAMLString()) + f = YAMLString(f) } + fmt.Printf("%s", f) } diff --git a/cmd/ghwc/commands/product.go b/cmd/ghwc/commands/product.go index 8b379b70..c50ba3ae 100644 --- a/cmd/ghwc/commands/product.go +++ b/cmd/ghwc/commands/product.go @@ -27,14 +27,7 @@ func showProduct(cmd *cobra.Command, args []string) error { return fmt.Errorf("error getting product info: %w", err) } - switch outputFormat { - case outputFormatHuman: - fmt.Printf("%v\n", product) - case outputFormatJSON: - fmt.Printf("%s\n", product.JSONString(pretty)) - case outputFormatYAML: - fmt.Printf("%s", product.YAMLString()) - } + printInfo(product) return nil } diff --git a/cmd/ghwc/commands/root.go b/cmd/ghwc/commands/root.go index 000c5c39..5ebd1543 100644 --- a/cmd/ghwc/commands/root.go +++ b/cmd/ghwc/commands/root.go @@ -118,13 +118,13 @@ func showAll(cmd *cobra.Command, args []string) error { if err != nil { return fmt.Errorf("error getting host info: %w", err) } - fmt.Printf("%s\n", host.JSONString(pretty)) + fmt.Printf("%s\n", JSONString(host, pretty)) case outputFormatYAML: host, err := ghw.Host() if err != nil { return fmt.Errorf("error getting host info: %w", err) } - fmt.Printf("%s", host.YAMLString()) + fmt.Printf("%s", YAMLString(host)) } return nil } diff --git a/cmd/ghwc/commands/topology.go b/cmd/ghwc/commands/topology.go index 650496ca..d08b0c14 100644 --- a/cmd/ghwc/commands/topology.go +++ b/cmd/ghwc/commands/topology.go @@ -43,9 +43,9 @@ func showTopology(cmd *cobra.Command, args []string) error { } } case outputFormatJSON: - fmt.Printf("%s\n", topology.JSONString(pretty)) + fmt.Printf("%s\n", JSONString(topology, pretty)) case outputFormatYAML: - fmt.Printf("%s", topology.YAMLString()) + fmt.Printf("%s", YAMLString(topology)) } return nil } diff --git a/cmd/ghwc/commands/usb.go b/cmd/ghwc/commands/usb.go index 53c9752c..b3fc2f02 100644 --- a/cmd/ghwc/commands/usb.go +++ b/cmd/ghwc/commands/usb.go @@ -27,17 +27,7 @@ func showUSB(cmd *cobra.Command, args []string) error { return fmt.Errorf("error getting USB info: %w", err) } - switch outputFormat { - case outputFormatHuman: - fmt.Printf("%v\n", usb) - for _, usb := range usb.Devices { - fmt.Printf(" %+v\n", usb) - } - case outputFormatJSON: - fmt.Printf("%s\n", usb.JSONString(pretty)) - case outputFormatYAML: - fmt.Printf("%s", usb.YAMLString()) - } + printInfo(usb) return nil } diff --git a/host.go b/host.go index 9c76b172..54781030 100644 --- a/host.go +++ b/host.go @@ -17,7 +17,6 @@ import ( "github.com/jaypipes/ghw/pkg/chassis" "github.com/jaypipes/ghw/pkg/cpu" "github.com/jaypipes/ghw/pkg/gpu" - "github.com/jaypipes/ghw/pkg/marshal" "github.com/jaypipes/ghw/pkg/memory" "github.com/jaypipes/ghw/pkg/net" "github.com/jaypipes/ghw/pkg/pci" @@ -138,15 +137,3 @@ func (info *HostInfo) String() string { info.USB.String(), ) } - -// YAMLString returns a string with the host information formatted as YAML -// under a top-level "host:" key -func (i *HostInfo) YAMLString() string { - return marshal.SafeYAML(i) -} - -// JSONString returns a string with the host information formatted as JSON -// under a top-level "host:" key -func (i *HostInfo) JSONString(indent bool) string { - return marshal.SafeJSON(i, indent) -} diff --git a/pkg/accelerator/accelerator.go b/pkg/accelerator/accelerator.go index c7dbc62f..d0b3c0df 100644 --- a/pkg/accelerator/accelerator.go +++ b/pkg/accelerator/accelerator.go @@ -10,7 +10,6 @@ import ( "fmt" "github.com/jaypipes/ghw/internal/config" - "github.com/jaypipes/ghw/pkg/marshal" "github.com/jaypipes/ghw/pkg/pci" ) @@ -61,21 +60,3 @@ func (i *Info) String() string { numDevsStr, ) } - -// simple private struct used to encapsulate processing accelerators information in a top-level -// "accelerator" YAML/JSON map/object key -type acceleratorPrinter struct { - Info *Info `json:"accelerator"` -} - -// YAMLString returns a string with the processing accelerators information formatted as YAML -// under a top-level "accelerator:" key -func (i *Info) YAMLString() string { - return marshal.SafeYAML(acceleratorPrinter{i}) -} - -// JSONString returns a string with the processing accelerators information formatted as JSON -// under a top-level "accelerator:" key -func (i *Info) JSONString(indent bool) string { - return marshal.SafeJSON(acceleratorPrinter{i}, indent) -} diff --git a/pkg/baseboard/baseboard.go b/pkg/baseboard/baseboard.go index 681f4fbe..a9e354d5 100644 --- a/pkg/baseboard/baseboard.go +++ b/pkg/baseboard/baseboard.go @@ -8,7 +8,6 @@ package baseboard import ( "github.com/jaypipes/ghw/internal/config" - "github.com/jaypipes/ghw/pkg/marshal" "github.com/jaypipes/ghw/pkg/util" ) @@ -58,21 +57,3 @@ func New(args ...any) (*Info, error) { } return info, nil } - -// simple private struct used to encapsulate baseboard information in a top-level -// "baseboard" YAML/JSON map/object key -type baseboardPrinter struct { - Info *Info `json:"baseboard"` -} - -// YAMLString returns a string with the baseboard information formatted as YAML -// under a top-level "dmi:" key -func (info *Info) YAMLString() string { - return marshal.SafeYAML(baseboardPrinter{info}) -} - -// JSONString returns a string with the baseboard information formatted as JSON -// under a top-level "baseboard:" key -func (info *Info) JSONString(indent bool) string { - return marshal.SafeJSON(baseboardPrinter{info}, indent) -} diff --git a/pkg/bios/bios.go b/pkg/bios/bios.go index 0961dc3c..ce37d195 100644 --- a/pkg/bios/bios.go +++ b/pkg/bios/bios.go @@ -10,7 +10,6 @@ import ( "fmt" "github.com/jaypipes/ghw/internal/config" - "github.com/jaypipes/ghw/pkg/marshal" "github.com/jaypipes/ghw/pkg/util" ) @@ -55,21 +54,3 @@ func New(args ...any) (*Info, error) { } return info, nil } - -// simple private struct used to encapsulate BIOS information in a top-level -// "bios" YAML/JSON map/object key -type biosPrinter struct { - Info *Info `json:"bios"` -} - -// YAMLString returns a string with the BIOS information formatted as YAML -// under a top-level "dmi:" key -func (info *Info) YAMLString() string { - return marshal.SafeYAML(biosPrinter{info}) -} - -// JSONString returns a string with the BIOS information formatted as JSON -// under a top-level "bios:" key -func (info *Info) JSONString(indent bool) string { - return marshal.SafeJSON(biosPrinter{info}, indent) -} diff --git a/pkg/block/block.go b/pkg/block/block.go index 9e2ec766..efd3605e 100644 --- a/pkg/block/block.go +++ b/pkg/block/block.go @@ -14,7 +14,6 @@ import ( "strings" "github.com/jaypipes/ghw/internal/config" - "github.com/jaypipes/ghw/pkg/marshal" "github.com/jaypipes/ghw/pkg/unitutil" "github.com/jaypipes/ghw/pkg/util" ) @@ -395,21 +394,3 @@ func (p *Partition) String() string { mountStr, ) } - -// simple private struct used to encapsulate block information in a top-level -// "block" YAML/JSON map/object key -type blockPrinter struct { - Info *Info `json:"block" yaml:"block"` -} - -// YAMLString returns a string with the block information formatted as YAML -// under a top-level "block:" key -func (i *Info) YAMLString() string { - return marshal.SafeYAML(blockPrinter{i}) -} - -// JSONString returns a string with the block information formatted as JSON -// under a top-level "block:" key -func (i *Info) JSONString(indent bool) string { - return marshal.SafeJSON(blockPrinter{i}, indent) -} diff --git a/pkg/chassis/chassis.go b/pkg/chassis/chassis.go index bb6b6c1c..b82c1ed0 100644 --- a/pkg/chassis/chassis.go +++ b/pkg/chassis/chassis.go @@ -8,7 +8,6 @@ package chassis import ( "github.com/jaypipes/ghw/internal/config" - "github.com/jaypipes/ghw/pkg/marshal" "github.com/jaypipes/ghw/pkg/util" ) @@ -95,21 +94,3 @@ func New(args ...any) (*Info, error) { } return info, nil } - -// simple private struct used to encapsulate chassis information in a top-level -// "chassis" YAML/JSON map/object key -type chassisPrinter struct { - Info *Info `json:"chassis"` -} - -// YAMLString returns a string with the chassis information formatted as YAML -// under a top-level "dmi:" key -func (info *Info) YAMLString() string { - return marshal.SafeYAML(chassisPrinter{info}) -} - -// JSONString returns a string with the chassis information formatted as JSON -// under a top-level "chassis:" key -func (info *Info) JSONString(indent bool) string { - return marshal.SafeJSON(chassisPrinter{info}, indent) -} diff --git a/pkg/cpu/cpu.go b/pkg/cpu/cpu.go index 91a9b4ca..79f3cfbe 100644 --- a/pkg/cpu/cpu.go +++ b/pkg/cpu/cpu.go @@ -10,7 +10,6 @@ import ( "fmt" "github.com/jaypipes/ghw/internal/config" - "github.com/jaypipes/ghw/pkg/marshal" ) // ProcessorCore describes a physical host processor core. A processor core is @@ -171,21 +170,3 @@ func (i *Info) String() string { nts, ) } - -// simple private struct used to encapsulate cpu information in a top-level -// "cpu" YAML/JSON map/object key -type cpuPrinter struct { - Info *Info `json:"cpu"` -} - -// YAMLString returns a string with the cpu information formatted as YAML -// under a top-level "cpu:" key -func (i *Info) YAMLString() string { - return marshal.SafeYAML(cpuPrinter{i}) -} - -// JSONString returns a string with the cpu information formatted as JSON -// under a top-level "cpu:" key -func (i *Info) JSONString(indent bool) string { - return marshal.SafeJSON(cpuPrinter{i}, indent) -} diff --git a/pkg/gpu/gpu.go b/pkg/gpu/gpu.go index a6207912..e1651c3c 100644 --- a/pkg/gpu/gpu.go +++ b/pkg/gpu/gpu.go @@ -10,7 +10,6 @@ import ( "fmt" "github.com/jaypipes/ghw/internal/config" - "github.com/jaypipes/ghw/pkg/marshal" "github.com/jaypipes/ghw/pkg/pci" "github.com/jaypipes/ghw/pkg/topology" ) @@ -79,15 +78,3 @@ func (i *Info) String() string { type gpuPrinter struct { Info *Info `json:"gpu"` } - -// YAMLString returns a string with the gpu information formatted as YAML -// under a top-level "gpu:" key -func (i *Info) YAMLString() string { - return marshal.SafeYAML(gpuPrinter{i}) -} - -// JSONString returns a string with the gpu information formatted as JSON -// under a top-level "gpu:" key -func (i *Info) JSONString(indent bool) string { - return marshal.SafeJSON(gpuPrinter{i}, indent) -} diff --git a/pkg/memory/memory.go b/pkg/memory/memory.go index e043adae..67c400a5 100644 --- a/pkg/memory/memory.go +++ b/pkg/memory/memory.go @@ -11,7 +11,6 @@ import ( "math" "github.com/jaypipes/ghw/internal/config" - "github.com/jaypipes/ghw/pkg/marshal" "github.com/jaypipes/ghw/pkg/unitutil" "github.com/jaypipes/ghw/pkg/util" ) @@ -94,21 +93,3 @@ func New(args ...any) (*Info, error) { func (i *Info) String() string { return i.Area.String() } - -// simple private struct used to encapsulate memory information in a top-level -// "memory" YAML/JSON map/object key -type memoryPrinter struct { - Info *Info `json:"memory"` -} - -// YAMLString returns a string with the memory information formatted as YAML -// under a top-level "memory:" key -func (i *Info) YAMLString() string { - return marshal.SafeYAML(memoryPrinter{i}) -} - -// JSONString returns a string with the memory information formatted as JSON -// under a top-level "memory:" key -func (i *Info) JSONString(indent bool) string { - return marshal.SafeJSON(memoryPrinter{i}, indent) -} diff --git a/pkg/net/net.go b/pkg/net/net.go index 21b7e621..b2b99ea7 100644 --- a/pkg/net/net.go +++ b/pkg/net/net.go @@ -10,7 +10,6 @@ import ( "fmt" "github.com/jaypipes/ghw/internal/config" - "github.com/jaypipes/ghw/pkg/marshal" ) // NICCapability is a feature/capability of a Network Interface Controller @@ -118,21 +117,3 @@ func (i *Info) String() string { len(i.NICs), ) } - -// simple private struct used to encapsulate net information in a -// top-level "net" YAML/JSON map/object key -type netPrinter struct { - Info *Info `json:"network"` -} - -// YAMLString returns a string with the net information formatted as YAML -// under a top-level "net:" key -func (i *Info) YAMLString() string { - return marshal.SafeYAML(netPrinter{i}) -} - -// JSONString returns a string with the net information formatted as JSON -// under a top-level "net:" key -func (i *Info) JSONString(indent bool) string { - return marshal.SafeJSON(netPrinter{i}, indent) -} diff --git a/pkg/pci/pci.go b/pkg/pci/pci.go index 38c8fcd5..023a45a0 100644 --- a/pkg/pci/pci.go +++ b/pkg/pci/pci.go @@ -14,7 +14,6 @@ import ( "github.com/jaypipes/ghw/internal/config" "github.com/jaypipes/ghw/internal/log" - "github.com/jaypipes/ghw/pkg/marshal" "github.com/jaypipes/ghw/pkg/topology" "github.com/jaypipes/ghw/pkg/util" ) @@ -175,21 +174,3 @@ func (info *Info) lookupDevice(address string) *Device { } return nil } - -// simple private struct used to encapsulate PCI information in a top-level -// "pci" YAML/JSON map/object key -type pciPrinter struct { - Info *Info `json:"pci"` -} - -// YAMLString returns a string with the PCI information formatted as YAML -// under a top-level "pci:" key -func (i *Info) YAMLString() string { - return marshal.SafeYAML(pciPrinter{i}) -} - -// JSONString returns a string with the PCI information formatted as JSON -// under a top-level "pci:" key -func (i *Info) JSONString(indent bool) string { - return marshal.SafeJSON(pciPrinter{i}, indent) -} diff --git a/pkg/pci/pci_linux_test.go b/pkg/pci/pci_linux_test.go index 2930f50b..b6bfb911 100644 --- a/pkg/pci/pci_linux_test.go +++ b/pkg/pci/pci_linux_test.go @@ -13,7 +13,6 @@ import ( "path/filepath" "testing" - "github.com/jaypipes/ghw/pkg/marshal" "github.com/jaypipes/ghw/pkg/option" "github.com/jaypipes/ghw/pkg/pci" "github.com/jaypipes/ghw/pkg/snapshot" @@ -198,9 +197,9 @@ func TestPCIMarshalJSON(t *testing.T) { if dev == nil { t.Fatalf("Failed to parse valid modalias") } - s := marshal.SafeJSON(dev, true) - if s == "" { - t.Fatalf("Error marshalling device: %v", dev) + _, err = json.MarshalIndent(&dev, "", " ") + if err != nil { + t.Fatalf("Error marshalling device %v, got %v", dev, err) } } diff --git a/pkg/product/product.go b/pkg/product/product.go index f1a1d189..7cf7539a 100644 --- a/pkg/product/product.go +++ b/pkg/product/product.go @@ -8,7 +8,6 @@ package product import ( "github.com/jaypipes/ghw/internal/config" - "github.com/jaypipes/ghw/pkg/marshal" "github.com/jaypipes/ghw/pkg/util" ) @@ -74,21 +73,3 @@ func New(args ...any) (*Info, error) { } return info, nil } - -// simple private struct used to encapsulate product information in a top-level -// "product" YAML/JSON map/object key -type productPrinter struct { - Info *Info `json:"product"` -} - -// YAMLString returns a string with the product information formatted as YAML -// under a top-level "dmi:" key -func (info *Info) YAMLString() string { - return marshal.SafeYAML(productPrinter{info}) -} - -// JSONString returns a string with the product information formatted as JSON -// under a top-level "product:" key -func (info *Info) JSONString(indent bool) string { - return marshal.SafeJSON(productPrinter{info}, indent) -} diff --git a/pkg/topology/topology.go b/pkg/topology/topology.go index 8faf8a60..24b5306f 100644 --- a/pkg/topology/topology.go +++ b/pkg/topology/topology.go @@ -15,7 +15,6 @@ import ( "github.com/jaypipes/ghw/internal/config" "github.com/jaypipes/ghw/pkg/cpu" - "github.com/jaypipes/ghw/pkg/marshal" "github.com/jaypipes/ghw/pkg/memory" ) @@ -136,21 +135,3 @@ func (i *Info) String() string { ) return res } - -// simple private struct used to encapsulate topology information in a -// top-level "topology" YAML/JSON map/object key -type topologyPrinter struct { - Info *Info `json:"topology"` -} - -// YAMLString returns a string with the topology information formatted as YAML -// under a top-level "topology:" key -func (i *Info) YAMLString() string { - return marshal.SafeYAML(topologyPrinter{i}) -} - -// JSONString returns a string with the topology information formatted as JSON -// under a top-level "topology:" key -func (i *Info) JSONString(indent bool) string { - return marshal.SafeJSON(topologyPrinter{i}, indent) -} diff --git a/pkg/usb/usb.go b/pkg/usb/usb.go index d446028f..ee3590ac 100644 --- a/pkg/usb/usb.go +++ b/pkg/usb/usb.go @@ -10,7 +10,6 @@ import ( "strings" "github.com/jaypipes/ghw/internal/config" - "github.com/jaypipes/ghw/pkg/marshal" ) type Device struct { @@ -92,21 +91,3 @@ func New(args ...any) (*Info, error) { } return info, nil } - -// simple private struct used to encapsulate usb information in a -// top-level "usb" YAML/JSON map/object key -type usbPrinter struct { - Info *Info `json:"usb"` -} - -// YAMLString returns a string with the net information formatted as YAML -// under a top-level "net:" key -func (i *Info) YAMLString() string { - return marshal.SafeYAML(usbPrinter{i}) -} - -// JSONString returns a string with the net information formatted as JSON -// under a top-level "net:" key -func (i *Info) JSONString(indent bool) string { - return marshal.SafeJSON(usbPrinter{i}, indent) -}