Skip to content

Commit aeb0475

Browse files
committed
Allow printing rule conditions in table output
1 parent c8a5f22 commit aeb0475

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

cmd/util.go

+7
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ func printTable(rows [][]string) {
5858
table := tablewriter.NewWriter(os.Stdout)
5959
table.SetAutoFormatHeaders(false)
6060
table.SetHeaderAlignment(tablewriter.ALIGN_LEFT)
61+
table.SetAutoWrapText(false)
6162
table.SetHeader(rows[0])
6263

6364
for _, row := range rows[1:] {
@@ -79,6 +80,12 @@ func reflectValueToString(v reflect.Value) string {
7980
}
8081
case reflect.Int:
8182
return strconv.Itoa(int(v.Int()))
83+
case reflect.Slice:
84+
values := []string{}
85+
for i := 0; i < v.Len(); i++ {
86+
values = append(values, reflectValueToString(v.Index(i)))
87+
}
88+
return strings.Join(values, ", ")
8289
default:
8390
if v.Type().Implements(stringerType) {
8491
return v.MethodByName("String").Call([]reflect.Value{})[0].String()

pkg/hue/hue_rules.go

+5
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package hue
22

33
import (
44
"encoding/json"
5+
"fmt"
56
)
67

78
type Rule struct {
@@ -30,6 +31,10 @@ type Condition struct {
3031
Value string
3132
}
3233

34+
func (v Condition) String() string {
35+
return fmt.Sprintf("%s %s \"%s\"", v.Address, v.Operator, v.Value)
36+
}
37+
3338
// GetRules gets a list of all rules that are in the bridge.
3439
func (h *Hue) GetRules() ([]Rule, error) {
3540
respBytes, err := h.API.GetRules()

0 commit comments

Comments
 (0)