fix(pkg/cli): nil pointer exeption - print empty string instead throw exeption

This commit is contained in:
Markus Pesch 2019-07-24 17:18:56 +02:00
parent 0dd156f480
commit 0e1ca7a8e1
Signed by: volker.raschek
GPG Key ID: 852BCC170D81A982

View File

@ -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()