lume/cmd/util.go

69 lines
1.2 KiB
Go
Raw Normal View History

2020-03-27 07:01:14 +00:00
package lumecmd
import (
"fmt"
"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
"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
})
}
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"
}
2021-03-29 22:22:22 +00:00
func Debugf(format string, a ...interface{}) {
if GetConfig().Debug {
fmt.Printf(format, a...)
}
2021-03-30 18:31:26 +00:00
}