refactor: temperature
This commit is contained in:
@ -1,34 +0,0 @@
|
||||
package temperature
|
||||
|
||||
import (
|
||||
"log"
|
||||
"os"
|
||||
|
||||
"git.cryptic.systems/fh-trier/go-flucky/pkg/temperature"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
var follow, push bool
|
||||
|
||||
var getTemperatureCmd = &cobra.Command{
|
||||
Use: "get",
|
||||
Short: "get temperature from sensor",
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
|
||||
if follow {
|
||||
if err := temperature.Follow(args, push, configDir, os.Stdout); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
} else {
|
||||
if err := temperature.Get(args, push, configDir, os.Stdout); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
func init() {
|
||||
temperatureCmd.AddCommand(getTemperatureCmd)
|
||||
getTemperatureCmd.Flags().BoolVarP(&follow, "follow", "f", false, "Follow output")
|
||||
getTemperatureCmd.Flags().BoolVarP(&push, "push", "p", false, "Push to remote server")
|
||||
}
|
@ -1,26 +0,0 @@
|
||||
package temperature
|
||||
|
||||
import (
|
||||
"log"
|
||||
"os"
|
||||
|
||||
"git.cryptic.systems/fh-trier/go-flucky/pkg/logs"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
var writeLog bool
|
||||
|
||||
var logTemperatureCmd = &cobra.Command{
|
||||
Use: "log",
|
||||
Short: "Log print all temperatures saved from logfile on stdout",
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
|
||||
if err := logs.ListTemperatures(configDir, os.Stdout); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
func init() {
|
||||
temperatureCmd.AddCommand(logTemperatureCmd)
|
||||
}
|
@ -1,23 +1,22 @@
|
||||
package temperature
|
||||
|
||||
import (
|
||||
"log"
|
||||
// import (
|
||||
// "log"
|
||||
|
||||
"git.cryptic.systems/fh-trier/go-flucky/pkg/temperature"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
// "github.com/spf13/cobra"
|
||||
// )
|
||||
|
||||
var pushTemperatureCmd = &cobra.Command{
|
||||
Use: "push",
|
||||
Short: "push temperature from sensor to remote servers",
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
// var pushTemperatureCmd = &cobra.Command{
|
||||
// Use: "push",
|
||||
// Short: "push temperature from sensor to remote servers",
|
||||
// Run: func(cmd *cobra.Command, args []string) {
|
||||
|
||||
if err := temperature.Push(configDir); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
},
|
||||
}
|
||||
// if err := temperature.Push(configDir); err != nil {
|
||||
// log.Fatal(err)
|
||||
// }
|
||||
// },
|
||||
// }
|
||||
|
||||
func init() {
|
||||
temperatureCmd.AddCommand(pushTemperatureCmd)
|
||||
}
|
||||
// func init() {
|
||||
// temperatureCmd.AddCommand(pushTemperatureCmd)
|
||||
// }
|
||||
|
41
cmd/temperature/read.go
Normal file
41
cmd/temperature/read.go
Normal file
@ -0,0 +1,41 @@
|
||||
package temperature
|
||||
|
||||
import (
|
||||
"log"
|
||||
"os"
|
||||
|
||||
"git.cryptic.systems/fh-trier/go-flucky/pkg/cli"
|
||||
"git.cryptic.systems/fh-trier/go-flucky/pkg/config"
|
||||
"git.cryptic.systems/fh-trier/go-flucky/pkg/sensor"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
var follow, push bool
|
||||
|
||||
var readTemperatureCmd = &cobra.Command{
|
||||
Use: "read",
|
||||
Short: "read temperature from sensor",
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
|
||||
// read configuration
|
||||
fc, err := config.Read(cfg)
|
||||
if err != nil {
|
||||
log.Fatalln(err)
|
||||
}
|
||||
|
||||
// FIXME:
|
||||
// add sensor entry to list
|
||||
temperatures, err := sensor.ReadTemperatures(fc.GetTemperatureSensors())
|
||||
if err != nil {
|
||||
log.Fatalln(err)
|
||||
}
|
||||
|
||||
cli.PrintTemperatures(temperatures, fc, os.Stdout)
|
||||
|
||||
},
|
||||
}
|
||||
|
||||
func init() {
|
||||
temperatureCmd.AddCommand(readTemperatureCmd)
|
||||
readTemperatureCmd.Flags().BoolVarP(&follow, "follow", "f", false, "Follow output")
|
||||
}
|
@ -1,19 +1,22 @@
|
||||
package temperature
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
var configDir string
|
||||
var cfg string
|
||||
|
||||
var temperatureCmd = &cobra.Command{
|
||||
Use: "temperature",
|
||||
Short: "Read temperature from sensor",
|
||||
Use: "temperature",
|
||||
Short: "",
|
||||
Example: fmt.Sprintf("flucky temperature read\nflucky temperature read outdoor"),
|
||||
}
|
||||
|
||||
// Execute a
|
||||
func InitCmd(cmd *cobra.Command, cnf string) {
|
||||
configDir = cnf
|
||||
func InitCmd(cmd *cobra.Command, config string) {
|
||||
cfg = config
|
||||
|
||||
cmd.AddCommand(temperatureCmd)
|
||||
|
||||
|
Reference in New Issue
Block a user