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
|
|
|
|
2019-06-15 13:58:41 +00:00
|
|
|
"github.com/go-flucky/flucky/pkg/cli"
|
|
|
|
"github.com/go-flucky/flucky/pkg/config"
|
|
|
|
"github.com/go-flucky/flucky/pkg/logfile"
|
2019-06-13 19:25:32 +00:00
|
|
|
"github.com/spf13/cobra"
|
|
|
|
)
|
|
|
|
|
|
|
|
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-16 11:00:50 +00:00
|
|
|
cnf, err := config.Read(configFile)
|
2019-06-15 12:02:35 +00:00
|
|
|
if err != nil {
|
|
|
|
log.Fatalln(err)
|
|
|
|
}
|
2019-06-13 19:25:32 +00:00
|
|
|
|
2019-06-19 17:18:01 +00:00
|
|
|
temperatureLogfile := logfile.New(cnf.Device.TemperatureLogfile)
|
|
|
|
|
|
|
|
temperatures, err := temperatureLogfile.ReadTemperatures()
|
2019-06-15 12:02:35 +00:00
|
|
|
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)
|
|
|
|
}
|