github.com/jaypipes/ghw@v0.21.1/cmd/ghwc/commands/topology.go (about) 1 // 2 // Use and distribution licensed under the Apache license version 2. 3 // 4 // See the COPYING file in the root project directory for full text. 5 // 6 7 package commands 8 9 import ( 10 "fmt" 11 12 "github.com/jaypipes/ghw" 13 "github.com/pkg/errors" 14 "github.com/spf13/cobra" 15 ) 16 17 // topologyCmd represents the install command 18 var topologyCmd = &cobra.Command{ 19 Use: "topology", 20 Short: "Show topology information for the host system", 21 RunE: showTopology, 22 } 23 24 // showTopology show topology information for the host system. 25 func showTopology(cmd *cobra.Command, args []string) error { 26 topology, err := ghw.Topology() 27 if err != nil { 28 return errors.Wrap(err, "error getting topology info") 29 } 30 31 switch outputFormat { 32 case outputFormatHuman: 33 fmt.Printf("%v\n", topology) 34 35 for _, node := range topology.Nodes { 36 fmt.Printf(" %v\n", node) 37 for _, cache := range node.Caches { 38 fmt.Printf(" %v\n", cache) 39 } 40 fmt.Printf(" %v\n", node.Memory) 41 fmt.Printf(" distances\n") 42 for nodeID, dist := range node.Distances { 43 fmt.Printf(" to node #%d %v\n", nodeID, dist) 44 } 45 } 46 case outputFormatJSON: 47 fmt.Printf("%s\n", topology.JSONString(pretty)) 48 case outputFormatYAML: 49 fmt.Printf("%s", topology.YAMLString()) 50 } 51 return nil 52 } 53 54 func init() { 55 rootCmd.AddCommand(topologyCmd) 56 }