Compare commits
No commits in common. "cb87159237140871657be69f75fef6e6db050ba0" and "617c2fccf9ea12995c1f535ecfd77fc011eb7be6" have entirely different histories.
cb87159237
...
617c2fccf9
@ -28,8 +28,6 @@ type Command struct {
|
||||
Func func(CmdArgs) (int, error)
|
||||
Flags *flag.FlagSet
|
||||
Use string
|
||||
Short string
|
||||
Long string
|
||||
}
|
||||
|
||||
var commandRegistry = make(map[string]Command)
|
||||
|
60
cmd/help.go
60
cmd/help.go
@ -1,60 +0,0 @@
|
||||
package lumecmd
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
func init() {
|
||||
var cmdName string = "help"
|
||||
fs := flag.NewFlagSet(cmdName, flag.ExitOnError)
|
||||
|
||||
RegisterCommand(cmdName, Command{
|
||||
Func: HelpCmd,
|
||||
Flags: fs,
|
||||
Use: "<command>",
|
||||
Short: "Show help for a command",
|
||||
})
|
||||
}
|
||||
|
||||
func HelpCmd(args CmdArgs) (int, error) {
|
||||
argv := args.Flags.Args()
|
||||
|
||||
if len(argv) == 0 {
|
||||
printHelp(commandRegistry)
|
||||
} else if len(argv) >= 1 {
|
||||
subCmd, ok := commandRegistry[argv[0]]
|
||||
if !ok {
|
||||
fmt.Printf("unknown command: %s\n", argv[0])
|
||||
return 1, nil
|
||||
}
|
||||
|
||||
if subCmd.Use != "" {
|
||||
fmt.Printf("usage:\n lume %s %s\n", subCmd.Name, subCmd.Use)
|
||||
fmt.Println()
|
||||
}
|
||||
|
||||
fmt.Print("flags:\n")
|
||||
subCmd.Flags.PrintDefaults()
|
||||
}
|
||||
|
||||
return 0, nil
|
||||
}
|
||||
|
||||
func printHelp(commands map[string]Command) {
|
||||
var maxLen, cmdLen int
|
||||
for _, c := range commands {
|
||||
cmdLen = len(c.Name)
|
||||
if cmdLen > maxLen {
|
||||
maxLen = cmdLen
|
||||
}
|
||||
}
|
||||
|
||||
fmt.Printf("usage:\n lume <command> [<args...>]")
|
||||
fmt.Println()
|
||||
|
||||
fmt.Println("\ncommands:")
|
||||
for _, c := range commands {
|
||||
fmt.Printf(" %-*s %s\n", maxLen, c.Name, c.Short)
|
||||
}
|
||||
}
|
@ -18,7 +18,6 @@ func init() {
|
||||
Func: LsCmd,
|
||||
Flags: fs,
|
||||
Use: "[--selector=<selector>",
|
||||
Short: "List the lights",
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -43,7 +43,6 @@ func init() {
|
||||
Func: SetColorCmd,
|
||||
Flags: fs,
|
||||
Use: "[--selector <selector>] [--power (on|off)] [--hue <hue>] [--saturation <saturation>] [--rgb <rbg>] [--name <color>] [--brightness <brightness>] [--duration <sec>] [--fast]",
|
||||
Short: "Set the color",
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -36,7 +36,6 @@ func init() {
|
||||
Func: SetStateCmd,
|
||||
Flags: fs,
|
||||
Use: "[--selector <selector>] [--power (on|off)] [--color <color>] [--brightness <brightness>] [--duration <sec>] [--infrared <infrared>] [--fast]",
|
||||
Short: "Set various state attributes",
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -39,7 +39,6 @@ func init() {
|
||||
Func: SetWhiteCmd,
|
||||
Flags: fs,
|
||||
Use: "[--selector <selector>] [--power (on|off)] [--kelvin <kelvin>] [--name <color>] [--brightness <brightness>] [--duration <sec>] [--infrared] [--fast]",
|
||||
Short: "Set the white level",
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -19,7 +19,6 @@ func init() {
|
||||
Func: ToggleCmd,
|
||||
Flags: fs,
|
||||
Use: "[--selector <selector>] [--duration <sec>]",
|
||||
Short: "Toggle the power on/off",
|
||||
})
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user