| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123 |
- package main
- import (
- "encoding/json"
- "fmt"
- "os"
- "github.com/spf13/cobra"
- "netdome.biz/paul/impact-80/cmd/qmk-rgb/rgb"
- "netdome.biz/paul/impact-80/internal/device"
- )
- // version is set at build time via -ldflags.
- var version = "dev"
- func newRootCommand() *cobra.Command {
- return &cobra.Command{
- Use: "qmk-rgb",
- Short: "QMK VIA RGB CLI — control VIA-compatible keyboard lighting",
- SilenceErrors: true,
- SilenceUsage: true,
- }
- }
- var rootCmd = newRootCommand()
- func Execute() {
- if err := rootCmd.Execute(); err != nil {
- fmt.Fprintf(os.Stderr, "Error: %v\n", err)
- os.Exit(1)
- }
- }
- func main() {
- Execute()
- }
- var keyboardCmd = &cobra.Command{
- Use: "keyboard",
- Short: "Keyboard management commands",
- }
- var keyboardInfoCmd = &cobra.Command{
- Use: "info",
- Short: "Discover connected VIA-compatible keyboards",
- Long: "Scan for connected VIA-compatible keyboards and print device info as JSON.",
- Run: func(cmd *cobra.Command, args []string) {
- keyboards, err := device.LoadKeyboards()
- if err != nil {
- fmt.Fprintf(os.Stderr, "Error: %v\n", err)
- os.Exit(1)
- }
- devices, err := device.Discover(keyboards)
- if err != nil {
- fmt.Fprintf(os.Stderr, "Error: %v\n", err)
- os.Exit(1)
- }
- if len(devices) == 0 {
- fmt.Println(`{"devices":[]}`)
- return
- }
- type Info struct {
- Devices []device.Device `json:"devices"`
- Total int `json:"total"`
- }
- out := Info{Devices: devices, Total: len(devices)}
- data, _ := json.MarshalIndent(out, "", " ")
- fmt.Println(string(data))
- },
- }
- var keyboardListCmd = &cobra.Command{
- Use: "list",
- Short: "List supported keyboards",
- Long: "Print all keyboards from keyboards.json as JSON.",
- Run: func(cmd *cobra.Command, args []string) {
- keyboards, err := device.LoadKeyboards()
- if err != nil {
- fmt.Fprintf(os.Stderr, "Error: %v\n", err)
- os.Exit(1)
- }
- if len(keyboards) == 0 {
- fmt.Println(`{"keyboards":[]}`)
- return
- }
- type Info struct {
- Keyboards []device.Keyboard `json:"keyboards"`
- Total int `json:"total"`
- }
- out := Info{Keyboards: keyboards, Total: len(keyboards)}
- data, _ := json.MarshalIndent(out, "", " ")
- fmt.Println(string(data))
- },
- }
- func init() {
- rootCmd.AddCommand(keyboardCmd)
- keyboardCmd.AddCommand(keyboardInfoCmd)
- keyboardCmd.AddCommand(keyboardListCmd)
- rgbCmd := rgb.Init()
- rgbCmd.AddCommand(
- rgb.NewEffectCmd(),
- rgb.NewBrightnessCmd(),
- rgb.NewSpeedCmd(),
- rgb.NewColorCmd(),
- rgb.NewModeCmd(),
- rgb.NewEnableCmd(),
- rgb.NewDisableCmd(),
- rgb.NewInfoCmd(),
- rgb.NewProfileSaveCmd(),
- rgb.NewProfileLoadCmd(),
- rgb.NewProfileListCmd(),
- rgb.NewProfileDeleteCmd(),
- )
- rootCmd.AddCommand(rgbCmd)
- rootCmd.Version = version
- rootCmd.SetVersionTemplate(" qmk-rgb {{.Version}}\n")
- }
|