2019-07-02 20:43:05 +00:00
|
|
|
package pressure
|
|
|
|
|
|
|
|
import (
|
2019-12-07 15:53:49 +00:00
|
|
|
"context"
|
2019-07-02 20:43:05 +00:00
|
|
|
"fmt"
|
|
|
|
"log"
|
|
|
|
"os"
|
|
|
|
|
|
|
|
"github.com/go-flucky/flucky/pkg/cli"
|
|
|
|
"github.com/go-flucky/flucky/pkg/config"
|
2019-12-07 15:53:49 +00:00
|
|
|
"github.com/go-flucky/flucky/pkg/storage"
|
2019-09-04 11:37:50 +00:00
|
|
|
"github.com/go-flucky/flucky/pkg/types"
|
2019-07-02 20:43:05 +00:00
|
|
|
"github.com/spf13/cobra"
|
|
|
|
)
|
|
|
|
|
|
|
|
var listTemperatureCmd = &cobra.Command{
|
|
|
|
Use: "list",
|
2019-07-02 20:54:58 +00:00
|
|
|
Short: "Reading temperature values from different or specified sensors by arguments",
|
2019-07-02 20:43:05 +00:00
|
|
|
Example: fmt.Sprintf("flucky pressure logs"),
|
|
|
|
Run: func(cmd *cobra.Command, args []string) {
|
|
|
|
|
|
|
|
// read configuration
|
2019-08-19 10:24:08 +00:00
|
|
|
cnf, err := config.Read(*configFile)
|
2019-07-02 20:43:05 +00:00
|
|
|
if err != nil {
|
|
|
|
log.Fatalln(err)
|
|
|
|
}
|
|
|
|
|
2019-12-07 15:53:49 +00:00
|
|
|
ctx := context.Background()
|
|
|
|
storageEndpoint, err := cnf.GetStorageEndpointURL()
|
2019-07-02 20:43:05 +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-07-02 20:43:05 +00:00
|
|
|
log.Fatalln(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
measuredValues = types.SelectMeasuredValues(types.MeasuredValueTypePressure, measuredValues)
|
|
|
|
|
|
|
|
cli.PrintMeasuredValues(measuredValues, cnf, os.Stdout)
|
|
|
|
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
pressureCmd.AddCommand(listTemperatureCmd)
|
|
|
|
}
|