2019-06-13 19:25:32 +00:00
|
|
|
package temperature
|
|
|
|
|
|
|
|
import (
|
2019-12-07 15:53:49 +00:00
|
|
|
"context"
|
2019-06-13 19:25:32 +00:00
|
|
|
"fmt"
|
2019-06-15 12:02:35 +00:00
|
|
|
"log"
|
|
|
|
"os"
|
2019-06-13 19:25:32 +00:00
|
|
|
|
2019-12-07 15:53:49 +00:00
|
|
|
"github.com/go-flucky/flucky/pkg/storage"
|
2019-07-02 20:33:01 +00:00
|
|
|
"github.com/go-flucky/flucky/pkg/types"
|
|
|
|
|
2019-06-15 13:58:41 +00:00
|
|
|
"github.com/go-flucky/flucky/pkg/cli"
|
|
|
|
"github.com/go-flucky/flucky/pkg/config"
|
2019-06-13 19:25:32 +00:00
|
|
|
"github.com/spf13/cobra"
|
|
|
|
)
|
|
|
|
|
|
|
|
var listTemperatureCmd = &cobra.Command{
|
|
|
|
Use: "list",
|
2019-07-02 20:54:58 +00:00
|
|
|
Short: "List temperature values from different or specified sensors by arguments",
|
2019-06-13 19:25:32 +00:00
|
|
|
Example: fmt.Sprintf("flucky temperature logs"),
|
|
|
|
Run: func(cmd *cobra.Command, args []string) {
|
|
|
|
|
|
|
|
// read configuration
|
2019-08-19 10:24:08 +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-12-07 15:53:49 +00:00
|
|
|
ctx := context.Background()
|
|
|
|
storageEndpoint, err := cnf.GetStorageEndpointURL()
|
2019-06-15 12:02:35 +00:00
|
|
|
if err != nil {
|
|
|
|
log.Fatalln(err)
|
|
|
|
}
|
|
|
|
|
2019-12-07 15:53:49 +00:00
|
|
|
measuredValues, err := storage.Read(ctx, storageEndpoint)
|
|
|
|
if err != nil {
|
2019-06-30 12:34:13 +00:00
|
|
|
log.Fatalln(err)
|
|
|
|
}
|
|
|
|
|
2019-07-02 20:33:01 +00:00
|
|
|
measuredValues = types.SelectMeasuredValues(types.MeasuredValueTypeTemperature, measuredValues)
|
2019-06-30 12:34:13 +00:00
|
|
|
|
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)
|
|
|
|
}
|