51 lines
1.1 KiB
Go
51 lines
1.1 KiB
Go
package rgbled
|
|
|
|
import (
|
|
"log"
|
|
|
|
"github.com/go-flucky/flucky/pkg/config"
|
|
"github.com/go-flucky/flucky/pkg/rgbled"
|
|
"github.com/go-flucky/flucky/pkg/types"
|
|
"github.com/spf13/cobra"
|
|
)
|
|
|
|
var onRgbLedCmd = &cobra.Command{
|
|
Use: "on",
|
|
Short: "Turn a RGB-LED color on",
|
|
Example: `flucky rgb-led on <names/uuids> <blue/green/purple/red/turquoise/white/yellow>
|
|
flucky rgb-led on my-led blue
|
|
flucky rgb-led on my-led my-sweet-led white
|
|
flucky rgb-led on 1c5b9424-f6e9-4a37-be5c-77e531e94aab red`,
|
|
Args: cobra.MinimumNArgs(1),
|
|
Run: func(cmd *cobra.Command, args []string) {
|
|
|
|
// read configuration
|
|
cnf, err := config.Read(*configFile)
|
|
if err != nil {
|
|
log.Fatalln(err)
|
|
}
|
|
|
|
rgbLEDs := make([]rgbled.RGBLED, 0)
|
|
if len(args) > 1 {
|
|
rgbLEDs = cnf.GetRGBLEDsByName(args[0 : len(args)-1])
|
|
} else {
|
|
rgbLEDs = cnf.GetRGBLEDs(config.ENABLED)
|
|
}
|
|
|
|
color, err := types.StringToLEDColor(args[len(args)-1])
|
|
if err != nil {
|
|
log.Fatalln(err)
|
|
}
|
|
|
|
err = rgbled.CustomColor(rgbLEDs, color)
|
|
if err != nil {
|
|
log.Fatalln(err)
|
|
}
|
|
|
|
},
|
|
}
|
|
|
|
func init() {
|
|
rgbLedCmd.AddCommand(onRgbLedCmd)
|
|
}
|