diff --git a/cmd/lume.go b/cmd/lume.go index 07a5456..43d761b 100644 --- a/cmd/lume.go +++ b/cmd/lume.go @@ -88,19 +88,7 @@ func main() { fmt.Println(err) os.Exit(1) } - calculateWidths(lights) - fmt.Printf("total %d\n", len(lights)) - for _, l := range lights { - fmt.Printf( - "%*s %*s %*s %*s %*s %-*s\n", - idWidth, l.Id, - locationWidth, l.Location.Name, - groupWidth, l.Group.Name, - labelWidth, l.Label, - lastSeenWidth, l.LastSeen.Local().Format(time.RFC3339), - powerWidth, PowerColor(l.Power), - ) - } + PrintLights(lights) case "set-state": setStateCommand.Parse(os.Args[4:]) @@ -215,6 +203,23 @@ func calculateWidths(lights []lifx.Light) { } } +func PrintLights(lights []lifx.Light) { + calculateWidths(lights) + + fmt.Printf("total %d\n", len(lights)) + for _, l := range lights { + fmt.Printf( + "%*s %*s %*s %*s %*s %-*s\n", + idWidth, l.Id, + locationWidth, l.Location.Name, + groupWidth, l.Group.Name, + labelWidth, l.Label, + lastSeenWidth, l.LastSeen.Local().Format(time.RFC3339), + powerWidth, PowerColor(l.Power), + ) + } +} + func PowerColor(s string) string { color := fc.New(fc.FgRed).SprintFunc() if s == "on" {