github.com/jaypipes/ghw@v0.21.1/cmd/ghwc/commands/accelerator.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 // acceleratorCmd represents the install command 18 var acceleratorCmd = &cobra.Command{ 19 Use: "accelerator", 20 Short: "Show processing accelerators information for the host system", 21 RunE: showGPU, 22 } 23 24 // showAccelerator show processing accelerators information for the host system. 25 func showAccelerator(cmd *cobra.Command, args []string) error { 26 accel, err := ghw.Accelerator() 27 if err != nil { 28 return errors.Wrap(err, "error getting Accelerator info") 29 } 30 31 switch outputFormat { 32 case outputFormatHuman: 33 fmt.Printf("%v\n", accel) 34 35 for _, card := range accel.Devices { 36 fmt.Printf(" %v\n", card) 37 } 38 case outputFormatJSON: 39 fmt.Printf("%s\n", accel.JSONString(pretty)) 40 case outputFormatYAML: 41 fmt.Printf("%s", accel.YAMLString()) 42 } 43 return nil 44 } 45 46 func init() { 47 rootCmd.AddCommand(acceleratorCmd) 48 }