2020-03-27 07:01:14 +00:00
|
|
|
package lumecmd
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2021-01-21 05:09:58 +00:00
|
|
|
"os"
|
2021-01-14 06:03:19 +00:00
|
|
|
"sort"
|
2020-03-28 23:04:53 +00:00
|
|
|
"strconv"
|
|
|
|
"strings"
|
2020-03-27 07:01:14 +00:00
|
|
|
|
2021-02-15 01:02:26 +00:00
|
|
|
"git.kill0.net/chill9/lifx-go"
|
2020-03-27 07:01:14 +00:00
|
|
|
)
|
|
|
|
|
2020-03-28 23:04:53 +00:00
|
|
|
func parseRGB(s string) (lifx.RGBColor, error) {
|
|
|
|
var c lifx.RGBColor
|
|
|
|
rgb := strings.SplitN(s, ",", 3)
|
|
|
|
r, err := strconv.ParseUint(rgb[0], 10, 8)
|
|
|
|
if err != nil {
|
|
|
|
return c, err
|
|
|
|
}
|
|
|
|
g, err := strconv.ParseUint(rgb[1], 10, 8)
|
|
|
|
if err != nil {
|
|
|
|
return c, err
|
|
|
|
}
|
|
|
|
b, err := strconv.ParseUint(rgb[2], 10, 8)
|
|
|
|
if err != nil {
|
|
|
|
return c, err
|
|
|
|
}
|
|
|
|
return lifx.NewRGBColor(uint8(r), uint8(g), uint8(b))
|
|
|
|
}
|
2021-01-14 06:03:19 +00:00
|
|
|
|
|
|
|
func sortLights(lights []lifx.Light) {
|
|
|
|
sort.Slice(lights, func(i, j int) bool {
|
|
|
|
if lights[i].Group.Name < lights[j].Group.Name {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
if lights[i].Group.Name > lights[j].Group.Name {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
return lights[i].Label < lights[j].Label
|
|
|
|
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func sortResults(res []lifx.Result) {
|
|
|
|
sort.Slice(res, func(i, j int) bool {
|
|
|
|
return res[i].Label < res[j].Label
|
|
|
|
})
|
|
|
|
}
|
2021-01-21 05:09:58 +00:00
|
|
|
|
|
|
|
func ExitWithCode(code int, err error) {
|
|
|
|
if err != nil {
|
|
|
|
fmt.Fprintf(os.Stderr, "%s\n", err)
|
|
|
|
}
|
|
|
|
os.Exit(code)
|
|
|
|
}
|
2021-02-15 05:06:12 +00:00
|
|
|
|
|
|
|
func YesNo(v bool) string {
|
|
|
|
if v {
|
|
|
|
return "yes"
|
|
|
|
}
|
|
|
|
return "no"
|
|
|
|
}
|