add named colors via the config file
This commit is contained in:
parent
3a6ee185fb
commit
f8e9dbc716
@ -10,7 +10,7 @@ import (
|
|||||||
|
|
||||||
type Config struct {
|
type Config struct {
|
||||||
AccessToken string
|
AccessToken string
|
||||||
Colors map[string]string `toml:"colors"`
|
Colors map[string][]float32 `toml:"colors"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type CmdArgs struct {
|
type CmdArgs struct {
|
||||||
@ -44,6 +44,7 @@ var (
|
|||||||
defaultHue string = ""
|
defaultHue string = ""
|
||||||
defaultSaturation string = ""
|
defaultSaturation string = ""
|
||||||
defaultRGB string = ""
|
defaultRGB string = ""
|
||||||
|
defaultName string = ""
|
||||||
)
|
)
|
||||||
|
|
||||||
func (f Flags) String(name string) string {
|
func (f Flags) String(name string) string {
|
||||||
|
@ -27,6 +27,9 @@ func init() {
|
|||||||
rgb := fs.String("rgb", defaultRGB, "RGB value")
|
rgb := fs.String("rgb", defaultRGB, "RGB value")
|
||||||
fs.StringVar(rgb, "r", defaultRGB, "RGB value")
|
fs.StringVar(rgb, "r", defaultRGB, "RGB value")
|
||||||
|
|
||||||
|
name := fs.String("name", defaultName, "named color")
|
||||||
|
fs.StringVar(name, "n", defaultName, "named color")
|
||||||
|
|
||||||
brightness := fs.String("brightness", defaultBrightness, "brightness state")
|
brightness := fs.String("brightness", defaultBrightness, "brightness state")
|
||||||
fs.StringVar(brightness, "b", defaultBrightness, "brightness state")
|
fs.StringVar(brightness, "b", defaultBrightness, "brightness state")
|
||||||
|
|
||||||
@ -57,6 +60,7 @@ func SetColorCmd(args CmdArgs) (int, error) {
|
|||||||
hueFlag := args.Flags.String("hue")
|
hueFlag := args.Flags.String("hue")
|
||||||
saturationFlag := args.Flags.String("saturation")
|
saturationFlag := args.Flags.String("saturation")
|
||||||
rgbFlag := args.Flags.String("rgb")
|
rgbFlag := args.Flags.String("rgb")
|
||||||
|
name := args.Flags.String("name")
|
||||||
|
|
||||||
if hueFlag != "" || saturationFlag != "" {
|
if hueFlag != "" || saturationFlag != "" {
|
||||||
color := lifx.HSBKColor{}
|
color := lifx.HSBKColor{}
|
||||||
@ -78,6 +82,16 @@ func SetColorCmd(args CmdArgs) (int, error) {
|
|||||||
return 1, err
|
return 1, err
|
||||||
}
|
}
|
||||||
state.Color = color
|
state.Color = color
|
||||||
|
} else if name != "" {
|
||||||
|
hsb, ok := args.Config.Colors[name]
|
||||||
|
if !ok {
|
||||||
|
return 1, fmt.Errorf("%s is not a defined color", name)
|
||||||
|
}
|
||||||
|
color, err := lifx.NewHSBColor(hsb[0], hsb[1], hsb[2])
|
||||||
|
if err != nil {
|
||||||
|
return 1, err
|
||||||
|
}
|
||||||
|
state.Color = color
|
||||||
}
|
}
|
||||||
|
|
||||||
brightnessFlag := args.Flags.String("brightness")
|
brightnessFlag := args.Flags.String("brightness")
|
||||||
|
Loading…
Reference in New Issue
Block a user