From 0e1ca7a8e127d9d30dc992efcdcb8d7667939048 Mon Sep 17 00:00:00 2001 From: Markus Pesch Date: Wed, 24 Jul 2019 17:18:56 +0200 Subject: [PATCH] fix(pkg/cli): nil pointer exeption - print empty string instead throw exeption --- pkg/cli/cli.go | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/pkg/cli/cli.go b/pkg/cli/cli.go index 29485e8..8f54a14 100644 --- a/pkg/cli/cli.go +++ b/pkg/cli/cli.go @@ -69,10 +69,36 @@ func PrintSensors(cnf *config.Configuration, w io.Writer) error { // declar tabwriter tw := tabwriter.NewWriter(w, 0, 0, 3, ' ', 0) - fmt.Fprint(tw, "name\tlocation\ttype\twire-id\tgpio\tenabled\n") + fmt.Fprint(tw, "name\tlocation\ttype\twire-id\ti2c-bus\ti2c-address\tgpio\tenabled\n") for _, sensor := range cnf.Sensors { - fmt.Fprintf(tw, "%v\t%v\t%v\t%v\t%v\t%v\n", sensor.SensorName, sensor.SensorLocation, sensor.SensorModel, *sensor.WireID, *sensor.GPIONumber, sensor.SensorEnabled) + fmt.Fprintf(tw, "%v\t%v\t%v\t", sensor.SensorName, sensor.SensorLocation, sensor.SensorModel) + + if sensor.WireID != nil { + fmt.Fprintf(tw, "%v\t", *sensor.WireID) + } else { + fmt.Fprintf(tw, "\t") + } + + if sensor.I2CBus != nil { + fmt.Fprintf(tw, "%v\t", *sensor.I2CBus) + } else { + fmt.Fprintf(tw, "\t") + } + + if sensor.I2CAddress != nil { + fmt.Fprintf(tw, "%v\t", *sensor.I2CAddress) + } else { + fmt.Fprintf(tw, "\t") + } + + if sensor.GPIONumber != nil { + fmt.Fprintf(tw, "%v\t", *sensor.GPIONumber) + } else { + fmt.Fprintf(tw, "\t") + } + + fmt.Fprintf(tw, "%v\n", sensor.SensorEnabled) } tw.Flush()