go.charczuk.com@v0.0.0-20240327042549-bc490516bd1a/experiments/huectl/pkg/command/set_light_color.go (about) 1 /* 2 3 Copyright (c) 2023 - Present. Will Charczuk. All rights reserved. 4 Use of this source code is governed by a MIT license that can be found in the LICENSE file at the root of the repository. 5 6 */ 7 8 package command 9 10 import ( 11 "github.com/urfave/cli/v2" 12 "go.charczuk.com/experiments/huectl/pkg/hue" 13 ) 14 15 // SetLightColor returns a command. 16 func SetLightColor() *cli.Command { 17 return &cli.Command{ 18 Name: "set-light-color", 19 Usage: "Set a given light to a given color.", 20 Flags: append( 21 DefaultFlags, 22 append(LightFlags, 23 &cli.StringFlag{ 24 Name: "color", 25 Aliases: []string{"c"}, 26 Usage: "The hex color to set the lights to (ex. #efefef)", 27 })..., 28 ), 29 Action: func(c *cli.Context) error { 30 light, _, err := lightHelper(c) 31 if err != nil { 32 return err 33 } 34 35 parsedColor := hue.ColorFromHex(c.String("color")) 36 if err = light.Color(c.Context, parsedColor); err != nil { 37 return err 38 } 39 40 printf(c, "light %q set to %s\n", light.Name, parsedColor.String()) 41 return nil 42 }, 43 } 44 }