fix: moved print functions into cli pkg

This commit is contained in:
Markus Pesch 2019-03-04 11:31:01 +01:00
parent 4bae510120
commit a243021c70
Signed by: volker.raschek
GPG Key ID: 852BCC170D81A982
4 changed files with 39 additions and 36 deletions

View File

@ -4,6 +4,7 @@ import (
"log" "log"
"os" "os"
"git.cryptic.systems/fh-trier/go-flucky/pkg/cli"
"git.cryptic.systems/fh-trier/go-flucky/pkg/config" "git.cryptic.systems/fh-trier/go-flucky/pkg/config"
"github.com/spf13/cobra" "github.com/spf13/cobra"
) )
@ -24,7 +25,7 @@ var listRemoteCmd = &cobra.Command{
} }
// print all configured remote addresses on stdout // print all configured remote addresses on stdout
err = fc.PrintRemotes(os.Stdout) err = cli.PrintRemotes(fc, os.Stdout)
if err != nil { if err != nil {
log.Fatalln(err) log.Fatalln(err)
} }

View File

@ -4,6 +4,7 @@ import (
"log" "log"
"os" "os"
"git.cryptic.systems/fh-trier/go-flucky/pkg/cli"
"git.cryptic.systems/fh-trier/go-flucky/pkg/config" "git.cryptic.systems/fh-trier/go-flucky/pkg/config"
"github.com/spf13/cobra" "github.com/spf13/cobra"
) )
@ -20,7 +21,7 @@ var listSensorCmd = &cobra.Command{
} }
// print sensors on stdout // print sensors on stdout
err = fc.PrintSensors(os.Stdout) err = cli.PrintSensors(fc, os.Stdout)
if err != nil { if err != nil {
log.Fatalln(err) log.Fatalln(err)
} }

View File

@ -9,6 +9,7 @@ import (
"git.cryptic.systems/fh-trier/go-flucky/pkg/types" "git.cryptic.systems/fh-trier/go-flucky/pkg/types"
) )
// PrintHumidities displays a list of humidities
func PrintHumidities(humidities []*types.Humidity, cnf *config.FluckyConfig, w io.Writer) { func PrintHumidities(humidities []*types.Humidity, cnf *config.FluckyConfig, w io.Writer) {
// determine all humidity sensors based on the humidiy values // determine all humidity sensors based on the humidiy values
sensors := []*types.Sensor{} sensors := []*types.Sensor{}
@ -66,6 +67,40 @@ func PrintHumidities(humidities []*types.Humidity, cnf *config.FluckyConfig, w i
tw.Flush() tw.Flush()
} }
// PrintRemotes displays a list with all configured remote addresses
func PrintRemotes(cnf *config.FluckyConfig, w io.Writer) error {
tw := tabwriter.NewWriter(w, 0, 0, 3, ' ', 0)
fmt.Fprint(tw, "name\taddress\tenabled\tregistered\n")
for _, remote := range cnf.Remotes {
fmt.Fprintf(tw, "%v\t%v\t%v\t%v\n", remote.Name, remote.Address, remote.Enabled, remote.Registered)
}
tw.Flush()
return nil
}
// PrintSensors displays a list with all configured sensors
func PrintSensors(cnf *config.FluckyConfig, 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")
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)
}
tw.Flush()
return nil
}
// PrintTemperatures displays a list of temperatures
func PrintTemperatures(temperatures []*types.Temperature, cnf *config.FluckyConfig, w io.Writer) { func PrintTemperatures(temperatures []*types.Temperature, cnf *config.FluckyConfig, w io.Writer) {
sensors := []*types.Sensor{} sensors := []*types.Sensor{}

View File

@ -5,7 +5,6 @@ import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"io" "io"
"text/tabwriter"
"time" "time"
"git.cryptic.systems/fh-trier/go-flucky/pkg/logger" "git.cryptic.systems/fh-trier/go-flucky/pkg/logger"
@ -302,39 +301,6 @@ func (fc *FluckyConfig) JSONWriter(w io.Writer) error {
return nil return nil
} }
// PrintRemotes displays a list with all configured remote addresses
func (fc *FluckyConfig) PrintRemotes(w io.Writer) error {
tw := tabwriter.NewWriter(w, 0, 0, 3, ' ', 0)
fmt.Fprint(tw, "name\taddress\tenabled\tregistered\n")
for _, remote := range fc.Remotes {
fmt.Fprintf(tw, "%v\t%v\t%v\t%v\n", remote.Name, remote.Address, remote.Enabled, remote.Registered)
}
tw.Flush()
return nil
}
// PrintSensors displays a list with all configured sensors
func (fc *FluckyConfig) PrintSensors(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")
for _, sensor := range fc.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)
}
tw.Flush()
return nil
}
// RemoveSensor deletes a sensor by its name or its unique UUID // RemoveSensor deletes a sensor by its name or its unique UUID
func (fc *FluckyConfig) RemoveSensor(nameOrUUID string) error { func (fc *FluckyConfig) RemoveSensor(nameOrUUID string) error {
for i, sensor := range fc.Sensors { for i, sensor := range fc.Sensors {