|
|
@@ -12,6 +12,14 @@ import (
|
|
|
// version is set at build time via -ldflags.
|
|
|
var version = "dev"
|
|
|
|
|
|
+// Group IDs for the root help. They name a group in the help output and say
|
|
|
+// nothing else: no behaviour hangs off them.
|
|
|
+const (
|
|
|
+ groupLighting = "lighting"
|
|
|
+ groupProfile = "profile"
|
|
|
+ groupKeyboard = "keyboard"
|
|
|
+)
|
|
|
+
|
|
|
var (
|
|
|
targetDevice string
|
|
|
targetZone string
|
|
|
@@ -24,6 +32,15 @@ func newRootCommand() *cobra.Command {
|
|
|
SilenceErrors: true,
|
|
|
SilenceUsage: true,
|
|
|
}
|
|
|
+ // The commands are grouped because fifteen of them in one flat list is where
|
|
|
+ // a user starts reading the help to find a command and gives up. A group says
|
|
|
+ // what a command is for, and a command in none of them lands under
|
|
|
+ // "Additional Commands" where the grouping says nothing.
|
|
|
+ cmd.AddGroup(
|
|
|
+ &cobra.Group{ID: groupLighting, Title: "Lighting Commands:"},
|
|
|
+ &cobra.Group{ID: groupProfile, Title: "Profile Commands:"},
|
|
|
+ &cobra.Group{ID: groupKeyboard, Title: "Keyboard Commands:"},
|
|
|
+ )
|
|
|
cmd.PersistentFlags().StringVar(&targetDevice, "device", "", "Keyboard number as printed by 'keyboard info', starting at 1")
|
|
|
cmd.PersistentFlags().StringVar(&targetZone, "zone", "", "RGB lighting channel: backlight, rgblight, rgb_matrix, audio or led_matrix, or the name this keyboard's definition gives it")
|
|
|
cmd.PersistentFlags().StringVar(&definitionFlag, "definition", "", "VIA definition file to read effect names from, instead of the one in the data directory")
|
|
|
@@ -45,8 +62,15 @@ func main() {
|
|
|
}
|
|
|
|
|
|
var keyboardCmd = &cobra.Command{
|
|
|
- Use: "keyboard",
|
|
|
- Short: "Keyboard management commands",
|
|
|
+ Use: "keyboard",
|
|
|
+ Short: "Keyboard management commands",
|
|
|
+ GroupID: groupKeyboard,
|
|
|
+}
|
|
|
+
|
|
|
+// inGroup places a command in one of the root help's groups.
|
|
|
+func inGroup(cmd *cobra.Command, group string) *cobra.Command {
|
|
|
+ cmd.GroupID = group
|
|
|
+ return cmd
|
|
|
}
|
|
|
|
|
|
// discoverAll is a seam for tests.
|
|
|
@@ -91,23 +115,32 @@ var keyboardInfoCmd = &cobra.Command{
|
|
|
}
|
|
|
|
|
|
func init() {
|
|
|
- rootCmd.AddCommand(keyboardCmd)
|
|
|
- keyboardCmd.AddCommand(keyboardInfoCmd)
|
|
|
-
|
|
|
- rootCmd.AddCommand(NewEnableCmd())
|
|
|
- rootCmd.AddCommand(NewDisableCmd())
|
|
|
- rootCmd.AddCommand(NewInfoCmd())
|
|
|
- rootCmd.AddCommand(NewEffectCmd())
|
|
|
- rootCmd.AddCommand(NewBrightnessCmd())
|
|
|
- rootCmd.AddCommand(NewSpeedCmd())
|
|
|
- rootCmd.AddCommand(NewColorCmd())
|
|
|
- rootCmd.AddCommand(NewModeCmd())
|
|
|
- rootCmd.AddCommand(NewProfileSaveCmd())
|
|
|
- rootCmd.AddCommand(NewProfileLoadCmd())
|
|
|
- rootCmd.AddCommand(NewProfileListCmd())
|
|
|
- rootCmd.AddCommand(NewProfileDeleteCmd())
|
|
|
- rootCmd.AddCommand(NewDefinitionCmd())
|
|
|
-
|
|
|
+ registerCommands(rootCmd)
|
|
|
rootCmd.Version = version
|
|
|
rootCmd.SetVersionTemplate(" qmk-rgb-tool {{.Version}}\n")
|
|
|
}
|
|
|
+
|
|
|
+// registerCommands adds every command to the root, each in the group the help
|
|
|
+// output lists it under. It is a function of its own so that a test can build the
|
|
|
+// same tree the binary runs and check the grouping is real, rather than repeating
|
|
|
+// a list that could fall behind the one that ships.
|
|
|
+func registerCommands(root *cobra.Command) {
|
|
|
+ keyboardCmd.AddCommand(keyboardInfoCmd)
|
|
|
+
|
|
|
+ root.AddCommand(
|
|
|
+ inGroup(NewEnableCmd(), groupLighting),
|
|
|
+ inGroup(NewDisableCmd(), groupLighting),
|
|
|
+ inGroup(NewInfoCmd(), groupLighting),
|
|
|
+ inGroup(NewEffectCmd(), groupLighting),
|
|
|
+ inGroup(NewBrightnessCmd(), groupLighting),
|
|
|
+ inGroup(NewSpeedCmd(), groupLighting),
|
|
|
+ inGroup(NewColorCmd(), groupLighting),
|
|
|
+ inGroup(NewModeCmd(), groupLighting),
|
|
|
+ inGroup(NewProfileSaveCmd(), groupProfile),
|
|
|
+ inGroup(NewProfileLoadCmd(), groupProfile),
|
|
|
+ inGroup(NewProfileListCmd(), groupProfile),
|
|
|
+ inGroup(NewProfileDeleteCmd(), groupProfile),
|
|
|
+ inGroup(NewDefinitionCmd(), groupKeyboard),
|
|
|
+ inGroup(keyboardCmd, groupKeyboard),
|
|
|
+ )
|
|
|
+}
|