Fantastic/cmd/root.go

49 lines
1.2 KiB
Go

package cmd
import (
"fmt"
"os"
"github.com/spf13/cobra"
"github.com/sstallion/go-hid"
"git.metaunix.net/metaunix/fantastic/devices"
)
var rootCmd = &cobra.Command{
Use: "fantastic",
Short: "Fantastic is a CLI app to manage ",
Long: `A fast and lightweight CLI tool to manage your Glorious peripherals.`,
Run: func(cmd *cobra.Command, args []string) {
count := 0
hid.Enumerate(0, 0, func(info *hid.DeviceInfo) error {
if info.VendorID == devices.VID {
count += 1
}
fmt.Printf("%s: ID %04x:%04x %s %s\n",
info.Path, info.VendorID, info.ProductID, info.MfrStr, info.ProductStr)
fmt.Println("Device Information:")
fmt.Printf("\tPath %s\n", info.Path)
fmt.Printf("\tVendorID %#04x\n", info.VendorID)
fmt.Printf("\tProductID %#04x\n", info.ProductID)
fmt.Printf("\tUsagePage %#04x\n", info.UsagePage)
fmt.Printf("\tUsage %#04x\n", info.Usage)
fmt.Printf("\tInterfaceNbr %d\n", info.InterfaceNbr)
fmt.Printf("\tBusType %s\n", info.BusType)
fmt.Println()
return nil
})
fmt.Printf("Found %d Glorious devices.\n", count)
},
}
func Execute() {
if err := rootCmd.Execute(); err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
}