Markus Pesch
5220eac16b
changes: - remove remote operations - add function to write measured values into a channel - add get humidity sensors from config - add get temperature sensors from config - remove FileLogger - exclude some functions from pkf into internal
59 lines
1.2 KiB
Go
59 lines
1.2 KiB
Go
package cmd
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
"time"
|
|
|
|
"github.com/volker-raschek/flucky/cmd/sensor"
|
|
"github.com/volker-raschek/flucky/cmd/temperature"
|
|
"github.com/volker-raschek/flucky/pkg/types"
|
|
|
|
uuid "github.com/satori/go.uuid"
|
|
"github.com/spf13/cobra"
|
|
"github.com/volker-raschek/flucky/pkg/config"
|
|
)
|
|
|
|
var configPath string
|
|
|
|
var rootCmd = &cobra.Command{
|
|
Use: "flucky",
|
|
Short: "Read from sensors",
|
|
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
|
|
|
|
// check if config file exists
|
|
if _, err := os.Stat(configPath); os.IsNotExist(err) {
|
|
hostname, err := os.Hostname()
|
|
if err != nil {
|
|
return fmt.Errorf("Can not locate the hostname: %v", err)
|
|
}
|
|
|
|
cnf := config.Configuration{
|
|
Device: &types.Device{
|
|
DeviceID: uuid.NewV4().String(),
|
|
DeviceName: hostname,
|
|
CreationDate: time.Now(),
|
|
},
|
|
}
|
|
|
|
err = config.Write(&cnf, configPath)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
}
|
|
|
|
return nil
|
|
},
|
|
}
|
|
|
|
// Execute a
|
|
func Execute(version string) {
|
|
rootCmd.Version = version
|
|
|
|
rootCmd.PersistentFlags().StringVar(&configPath, "config", "/etc/flucky/config.json", "Config file")
|
|
// humidity.InitCmd(rootCmd, configDir)
|
|
sensor.InitCmd(rootCmd, configPath)
|
|
temperature.InitCmd(rootCmd, configPath)
|
|
rootCmd.Execute()
|
|
}
|