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-25 20:56:09 +00:00
|
|
|
logfile := logfile.New(cnf)
|
2019-06-19 17:18:01 +00:00
|
|
|
|
2019-06-25 20:56:09 +00:00
|
|
|
measuredValues, err := logfile.Read()
|
2019-06-15 12:02:35 +00:00
|
|
|
if err != nil {
|
|
|
|
log.Fatalln(err)
|
|
|
|
}
|
|
|
|
|
2019-06-25 20:56:09 +00:00
|
|
|
cli.PrintMeasuredValues(measuredValues, cnf, os.Stdout)
|
2019-06-13 19:25:32 +00:00
|
|
|
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
temperatureCmd.AddCommand(listTemperatureCmd)
|
|
|
|
}
|