fix(cmd): configPath variable

This commit is contained in:
Markus Pesch 2019-06-15 14:25:45 +02:00
parent 258ac998be
commit 82faa1d536
Signed by: volker.raschek
GPG Key ID: 852BCC170D81A982
7 changed files with 20 additions and 18 deletions

View File

@ -53,7 +53,7 @@ func Execute(version string) {
rootCmd.Version = version rootCmd.Version = version
rootCmd.PersistentFlags().StringVar(&configPath, "config", "/etc/flucky/config.json", "Config file") rootCmd.PersistentFlags().StringVar(&configPath, "config", "/etc/flucky/config.json", "Config file")
// humidity.InitCmd(rootCmd, configDir) // humidity.InitCmd(rootCmd, configPath)
sensor.InitCmd(rootCmd, configPath) sensor.InitCmd(rootCmd, configPath)
temperature.InitCmd(rootCmd, configPath) temperature.InitCmd(rootCmd, configPath)
rootCmd.Execute() rootCmd.Execute()

View File

@ -4,18 +4,23 @@ import (
"github.com/spf13/cobra" "github.com/spf13/cobra"
) )
var configDir string var configPath string
var daemonCmd = &cobra.Command{ var daemonCmd = &cobra.Command{
Use: "daemon", Use: "daemon",
Short: "Read continuously data from all enabled sensors", Short: "Read continuously data from all enabled sensors",
Run: func(cmd *cobra.Command, args []string) { Run: func(cmd *cobra.Command, args []string) {
// read configuration
// cnf, err := config.Read(configPath)
// if err != nil {
// log.Fatalln(err)
// }
}, },
} }
func InitCmd(cmd *cobra.Command, cnf string) { func InitCmd(cmd *cobra.Command, cnfPath string) {
configDir = cnf configPath = cnfPath
cmd.AddCommand(daemonCmd) cmd.AddCommand(daemonCmd)

View File

@ -1,10 +1,7 @@
package humidity package humidity
import ( import (
"log"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"github.com/volker-raschek/flucky/pkg/humidity"
) )
var follow, push bool var follow, push bool
@ -14,9 +11,9 @@ var getHumidityCmd = &cobra.Command{
Short: "get humidity from sensor", Short: "get humidity from sensor",
Run: func(cmd *cobra.Command, args []string) { Run: func(cmd *cobra.Command, args []string) {
if err := humidity.Get(); err != nil { // if err := humidity.Get(); err != nil {
log.Fatal(err) // log.Fatal(err)
} // }
}, },
} }

View File

@ -4,7 +4,7 @@ import (
"github.com/spf13/cobra" "github.com/spf13/cobra"
) )
var configDir string var configPath string
var humidityCmd = &cobra.Command{ var humidityCmd = &cobra.Command{
Use: "humidity", Use: "humidity",
@ -12,8 +12,8 @@ var humidityCmd = &cobra.Command{
} }
// Execute a // Execute a
func InitCmd(cmd *cobra.Command, cnf string) { func InitCmd(cmd *cobra.Command, cnfPath string) {
configDir = cnf configPath = cnfPath
cmd.AddCommand(humidityCmd) cmd.AddCommand(humidityCmd)

View File

@ -18,7 +18,7 @@ var listTemperatureCmd = &cobra.Command{
Run: func(cmd *cobra.Command, args []string) { Run: func(cmd *cobra.Command, args []string) {
// read configuration // read configuration
cnf, err := config.Read(cnfPath) cnf, err := config.Read(configPath)
if err != nil { if err != nil {
log.Fatalln(err) log.Fatalln(err)
} }

View File

@ -22,7 +22,7 @@ var readTemperatureCmd = &cobra.Command{
Run: func(cmd *cobra.Command, args []string) { Run: func(cmd *cobra.Command, args []string) {
// read configuration // read configuration
cnf, err := config.Read(cnfPath) cnf, err := config.Read(configPath)
if err != nil { if err != nil {
log.Fatalln(err) log.Fatalln(err)
} }

View File

@ -6,7 +6,7 @@ import (
"github.com/spf13/cobra" "github.com/spf13/cobra"
) )
var cnfPath string var configPath string
var temperatureCmd = &cobra.Command{ var temperatureCmd = &cobra.Command{
Use: "temperature", Use: "temperature",
@ -15,8 +15,8 @@ var temperatureCmd = &cobra.Command{
} }
// Execute a // Execute a
func InitCmd(cmd *cobra.Command, configPath string) { func InitCmd(cmd *cobra.Command, cnfPath string) {
cnfPath = configPath configPath = cnfPath
cmd.AddCommand(temperatureCmd) cmd.AddCommand(temperatureCmd)
} }