2019-06-13 19:25:32 +00:00
|
|
|
package temperature
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2019-06-15 12:02:35 +00:00
|
|
|
"log"
|
|
|
|
"os"
|
2019-06-13 19:25:32 +00:00
|
|
|
|
|
|
|
"github.com/spf13/cobra"
|
2019-06-15 12:02:35 +00:00
|
|
|
"github.com/volker-raschek/flucky/pkg/cli"
|
|
|
|
"github.com/volker-raschek/flucky/pkg/config"
|
|
|
|
"github.com/volker-raschek/flucky/pkg/logfile"
|
2019-06-13 19:25:32 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
var listTemperatureCmd = &cobra.Command{
|
|
|
|
Use: "list",
|
|
|
|
Short: "print temperatures",
|
|
|
|
Example: fmt.Sprintf("flucky temperature logs"),
|
|
|
|
Run: func(cmd *cobra.Command, args []string) {
|
|
|
|
|
|
|
|
// read configuration
|
2019-06-15 12:02:35 +00:00
|
|
|
cnf, err := config.Read(cnfPath)
|
|
|
|
if err != nil {
|
|
|
|
log.Fatalln(err)
|
|
|
|
}
|
2019-06-13 19:25:32 +00:00
|
|
|
|
2019-06-15 12:02:35 +00:00
|
|
|
temperatures, err := logfile.ReadTemperatures(cnf.Device.TemperatureLogfile)
|
|
|
|
if err != nil {
|
|
|
|
log.Fatalln(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
cli.PrintTemperatures(temperatures, cnf, os.Stdout)
|
2019-06-13 19:25:32 +00:00
|
|
|
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
temperatureCmd.AddCommand(listTemperatureCmd)
|
|
|
|
}
|