2023-05-25 15:55:21 -04:00
|
|
|
package cmd
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"os"
|
|
|
|
|
|
|
|
"github.com/spf13/cobra"
|
2023-05-25 16:56:26 -04:00
|
|
|
"github.com/sstallion/go-hid"
|
|
|
|
|
|
|
|
"git.metaunix.net/metaunix/fantastic/devices"
|
2023-05-25 15:55:21 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
var rootCmd = &cobra.Command{
|
2023-05-25 16:56:26 -04:00
|
|
|
Use: "fantastic",
|
|
|
|
Short: "Fantastic is a CLI app to manage ",
|
|
|
|
Long: `A fast and lightweight CLI tool to manage your Glorious peripherals.`,
|
2023-05-25 15:55:21 -04:00
|
|
|
Run: func(cmd *cobra.Command, args []string) {
|
2023-05-25 16:56:26 -04:00
|
|
|
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)
|
2023-05-25 15:55:21 -04:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
func Execute() {
|
|
|
|
if err := rootCmd.Execute(); err != nil {
|
|
|
|
fmt.Fprintln(os.Stderr, err)
|
|
|
|
os.Exit(1)
|
|
|
|
}
|
|
|
|
}
|