fix(cli/db): remove obsolete db subcommand

This commit is contained in:
2019-12-07 18:57:41 +01:00
parent dbef4f8241
commit b125bf432c
6 changed files with 32 additions and 79 deletions

View File

@ -36,13 +36,13 @@ var rootCmd = &cobra.Command{
return fmt.Errorf("Can not locate the hostname: %v", err)
}
// Time must be truncted for postgres
// Postgres currently does not support nanoseconds which is automatically
// include into the go time object
// Time must be truncted for postgres. Postgres currently does not support
// nanoseconds which is automatically include into the go time object
t := time.Now()
l, _ := time.LoadLocation("Europe/Berlin")
t = time.Date(t.Year(), t.Month(), t.Day(), t.Hour(), t.Minute(), t.Second(), int(math.Round(float64(t.Nanosecond())/1000000)*1000000), l)
// Default configuration
cnf := config.Configuration{
Device: &types.Device{
DeviceID: uuid.NewV4().String(),
@ -71,7 +71,6 @@ func Execute(version *semver.Version) {
compression.InitCmd(rootCmd, &configFile, version)
convert.InitCmd(rootCmd, &configFile, version)
daemon.InitCmd(rootCmd, &configFile, version)
// db.InitCmd(rootCmd, &configFile, version)
humidity.InitCmd(rootCmd, &configFile, version)
pressure.InitCmd(rootCmd, &configFile, version)
rgbled.InitCmd(rootCmd, &configFile, version)

View File

@ -1,56 +0,0 @@
package db
import (
"github.com/Masterminds/semver"
"github.com/spf13/cobra"
)
var (
configFile *string
version *semver.Version
)
var dbCmd = &cobra.Command{
Use: "db",
Short: "Operates with the configured database",
Run: func(cmd *cobra.Command, args []string) {
// // read configuration
// cnf, err := config.Read(*configFile)
// if err != nil {
// log.Fatalln(err)
// }
// postgresDB, err := database.New(cnf.DatabaseSettings)
// if err != nil {
// log.Fatalf("%v", err)
// }
// ctx := context.Background()
// devices := []*types.Device{
// &types.Device{
// DeviceID: "1684df26-bc72-4435-a4f9-74b24bdb286c",
// DeviceName: "raspberr-pi",
// },
// &types.Device{
// DeviceID: "1684df26-bc72-4435-a4f9-74b24bdb286c",
// DeviceName: "raspberr-pi",
// },
// }
// if err := postgresDB.InsertDevices(ctx, devices); err != nil {
// log.Fatalln(err)
// }
},
}
// Execute a
func InitCmd(cmd *cobra.Command, cnfFile *string, sversion *semver.Version) {
configFile = cnfFile
version = sversion
cmd.AddCommand(dbCmd)
}

View File

@ -15,8 +15,6 @@ import (
"github.com/spf13/cobra"
)
var logs bool
var readTemperatureCmd = &cobra.Command{
Use: "read",
Short: "Reading temperature values from different or specified sensors by arguments",
@ -38,7 +36,7 @@ var readTemperatureCmd = &cobra.Command{
}
if len(sensors) == 0 {
return
log.Fatalln("No sensors found, specified or configured")
}
ctx := context.Background()
@ -47,12 +45,20 @@ var readTemperatureCmd = &cobra.Command{
log.Fatalln(err)
}
storage.Round(measuredValues, round)
measuredValues = types.SelectMeasuredValues(types.MeasuredValueTypeTemperature, measuredValues)
// print temperatures on stdout
cli.PrintMeasuredValues(measuredValues, cnf, os.Stdout)
// Save the new measured values, if desired
if logs {
if compression {
measuredValues = storage.Compression(measuredValues)
}
storageEndpoint, err := cnf.GetStorageEndpointURL()
if err != nil {
log.Fatalln(err)

View File

@ -10,6 +10,7 @@ import (
var (
compression bool
configFile *string
logs bool
round float64
version *semver.Version
@ -21,7 +22,7 @@ var temperatureCmd = &cobra.Command{
Example: fmt.Sprintf("flucky temperature read\nflucky temperature read outdoor"),
}
// Execute a
// InitCmd initialize the subcommand
func InitCmd(cmd *cobra.Command, cnfFile *string, sversion *semver.Version) {
configFile = cnfFile
version = sversion