PKGBUILD/cmd/temperature/read.go

47 lines
1016 B
Go

package temperature
import (
"log"
"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/sensor"
"github.com/spf13/cobra"
)
var follow, push bool
var readTemperatureCmd = &cobra.Command{
Use: "read",
Short: "read temperature from sensor",
Run: func(cmd *cobra.Command, args []string) {
// read configuration
fc, err := config.Read(cfg)
if err != nil {
log.Fatalln(err)
}
// fetch all temperature sensors
temperatureSensors, err := fc.GetTemperatureSensors()
if err != nil {
log.Fatalln(err)
}
// read temperature from sensors
temperatures, err := sensor.ReadTemperatures(temperatureSensors)
if err != nil {
log.Fatalln(err)
}
// print temperatures on stdout
cli.PrintTemperatures(temperatures, fc, os.Stdout)
},
}
func init() {
temperatureCmd.AddCommand(readTemperatureCmd)
readTemperatureCmd.Flags().BoolVarP(&follow, "follow", "f", false, "Follow output")
}