From c0aa155f36739962b96b3f1e2040c48045dd1585 Mon Sep 17 00:00:00 2001 From: Markus Pesch Date: Mon, 19 Aug 2019 12:24:08 +0200 Subject: [PATCH] fix(cmd): use pointer instead a copied object of the configFile environment --- cmd/cmd.go | 19 +++++++++---------- cmd/compression/compression.go | 4 ++-- cmd/convert/convert.go | 4 ++-- cmd/daemon/daemon.go | 6 +++--- cmd/humidity/humidity.go | 4 ++-- cmd/humidity/list.go | 2 +- cmd/humidity/read.go | 2 +- cmd/pressure/list.go | 2 +- cmd/pressure/pressure.go | 4 ++-- cmd/pressure/read.go | 2 +- cmd/rgbled/add.go | 4 ++-- cmd/rgbled/disable.go | 4 ++-- cmd/rgbled/enable.go | 4 ++-- cmd/rgbled/list.go | 2 +- cmd/rgbled/off.go | 2 +- cmd/rgbled/on.go | 2 +- cmd/rgbled/remove.go | 4 ++-- cmd/rgbled/rename.go | 4 ++-- cmd/rgbled/rgbled.go | 4 ++-- cmd/sensor/add.go | 4 ++-- cmd/sensor/disable.go | 4 ++-- cmd/sensor/enable.go | 4 ++-- cmd/sensor/list.go | 4 ++-- cmd/sensor/remove.go | 4 ++-- cmd/sensor/rename.go | 4 ++-- cmd/sensor/sensor.go | 4 ++-- cmd/temperature/list.go | 2 +- cmd/temperature/read.go | 2 +- cmd/temperature/temperature.go | 4 ++-- 29 files changed, 57 insertions(+), 58 deletions(-) diff --git a/cmd/cmd.go b/cmd/cmd.go index 423428e..3ab3a76 100644 --- a/cmd/cmd.go +++ b/cmd/cmd.go @@ -7,10 +7,9 @@ import ( "github.com/go-flucky/flucky/cmd/compression" "github.com/go-flucky/flucky/cmd/convert" - "github.com/go-flucky/flucky/cmd/pressure" - "github.com/go-flucky/flucky/cmd/daemon" "github.com/go-flucky/flucky/cmd/humidity" + "github.com/go-flucky/flucky/cmd/pressure" "github.com/go-flucky/flucky/cmd/rgbled" "github.com/go-flucky/flucky/cmd/sensor" "github.com/go-flucky/flucky/cmd/temperature" @@ -60,13 +59,13 @@ func Execute(version string) { rootCmd.PersistentFlags().StringVar(&configFile, "config", "/etc/flucky/config.json", "Config file") - compression.InitCmd(rootCmd, configFile) - convert.InitCmd(rootCmd, configFile) - daemon.InitCmd(rootCmd, configFile) - humidity.InitCmd(rootCmd, configFile) - pressure.InitCmd(rootCmd, configFile) - rgbled.InitCmd(rootCmd, configFile) - sensor.InitCmd(rootCmd, configFile) - temperature.InitCmd(rootCmd, configFile) + compression.InitCmd(rootCmd, &configFile) + convert.InitCmd(rootCmd, &configFile) + daemon.InitCmd(rootCmd, &configFile) + humidity.InitCmd(rootCmd, &configFile) + pressure.InitCmd(rootCmd, &configFile) + rgbled.InitCmd(rootCmd, &configFile) + sensor.InitCmd(rootCmd, &configFile) + temperature.InitCmd(rootCmd, &configFile) rootCmd.Execute() } diff --git a/cmd/compression/compression.go b/cmd/compression/compression.go index ed3891b..463bb24 100644 --- a/cmd/compression/compression.go +++ b/cmd/compression/compression.go @@ -9,7 +9,7 @@ import ( ) var compression bool -var configFile string +var configFile *string var compressionCmd = &cobra.Command{ Use: "compression", @@ -33,7 +33,7 @@ var compressionCmd = &cobra.Command{ }, } -func InitCmd(cmd *cobra.Command, cnfFile string) { +func InitCmd(cmd *cobra.Command, cnfFile *string) { configFile = cnfFile cmd.AddCommand(compressionCmd) diff --git a/cmd/convert/convert.go b/cmd/convert/convert.go index d5d67e5..554c88f 100644 --- a/cmd/convert/convert.go +++ b/cmd/convert/convert.go @@ -9,7 +9,7 @@ import ( ) var compression bool -var configFile string +var configFile *string var convertCmd = &cobra.Command{ Use: "convert", @@ -37,7 +37,7 @@ var convertCmd = &cobra.Command{ } // Execute a -func InitCmd(cmd *cobra.Command, cnfFile string) { +func InitCmd(cmd *cobra.Command, cnfFile *string) { configFile = cnfFile cmd.AddCommand(convertCmd) convertCmd.Flags().BoolVar(&compression, "compression", true, "Compress measured values") diff --git a/cmd/daemon/daemon.go b/cmd/daemon/daemon.go index 827ed00..bbd1bfb 100644 --- a/cmd/daemon/daemon.go +++ b/cmd/daemon/daemon.go @@ -12,7 +12,7 @@ import ( var cleanCacheInterval string var compression bool -var configFile string +var configFile *string var round float64 var temperatureUnit string @@ -21,7 +21,7 @@ var daemonCmd = &cobra.Command{ Short: "Read continuously data from all enabled sensors", Run: func(cmd *cobra.Command, args []string) { // read configuration - cnf, err := config.Read(configFile) + cnf, err := config.Read(*configFile) if err != nil { log.Fatalln(err) } @@ -38,7 +38,7 @@ var daemonCmd = &cobra.Command{ }, } -func InitCmd(cmd *cobra.Command, cnfFile string) { +func InitCmd(cmd *cobra.Command, cnfFile *string) { configFile = cnfFile cmd.AddCommand(daemonCmd) daemonCmd.Flags().BoolVar(&compression, "compression", true, "Compress measured values") diff --git a/cmd/humidity/humidity.go b/cmd/humidity/humidity.go index 973a61c..ac7ed9f 100644 --- a/cmd/humidity/humidity.go +++ b/cmd/humidity/humidity.go @@ -5,7 +5,7 @@ import ( ) var compression bool -var configFile string +var configFile *string var round float64 var humidityCmd = &cobra.Command{ @@ -14,7 +14,7 @@ var humidityCmd = &cobra.Command{ } // Execute a -func InitCmd(cmd *cobra.Command, cnfFile string) { +func InitCmd(cmd *cobra.Command, cnfFile *string) { configFile = cnfFile cmd.AddCommand(humidityCmd) diff --git a/cmd/humidity/list.go b/cmd/humidity/list.go index 1518188..3b60c36 100644 --- a/cmd/humidity/list.go +++ b/cmd/humidity/list.go @@ -21,7 +21,7 @@ var listTemperatureCmd = &cobra.Command{ Run: func(cmd *cobra.Command, args []string) { // read configuration - cnf, err := config.Read(configFile) + cnf, err := config.Read(*configFile) if err != nil { log.Fatalln(err) } diff --git a/cmd/humidity/read.go b/cmd/humidity/read.go index 0d4eb86..326f0a3 100644 --- a/cmd/humidity/read.go +++ b/cmd/humidity/read.go @@ -23,7 +23,7 @@ var readHumidityCmd = &cobra.Command{ Run: func(cmd *cobra.Command, args []string) { // read configuration - cnf, err := config.Read(configFile) + cnf, err := config.Read(*configFile) if err != nil { log.Fatalln(err) } diff --git a/cmd/pressure/list.go b/cmd/pressure/list.go index 25c63d3..8e256c5 100644 --- a/cmd/pressure/list.go +++ b/cmd/pressure/list.go @@ -21,7 +21,7 @@ var listTemperatureCmd = &cobra.Command{ Run: func(cmd *cobra.Command, args []string) { // read configuration - cnf, err := config.Read(configFile) + cnf, err := config.Read(*configFile) if err != nil { log.Fatalln(err) } diff --git a/cmd/pressure/pressure.go b/cmd/pressure/pressure.go index a1a01a9..4f75206 100644 --- a/cmd/pressure/pressure.go +++ b/cmd/pressure/pressure.go @@ -5,7 +5,7 @@ import ( ) var compression bool -var configFile string +var configFile *string var round float64 var pressureCmd = &cobra.Command{ @@ -14,7 +14,7 @@ var pressureCmd = &cobra.Command{ } // Execute a -func InitCmd(cmd *cobra.Command, cnfFile string) { +func InitCmd(cmd *cobra.Command, cnfFile *string) { configFile = cnfFile cmd.AddCommand(pressureCmd) diff --git a/cmd/pressure/read.go b/cmd/pressure/read.go index b6c0979..bb94c30 100644 --- a/cmd/pressure/read.go +++ b/cmd/pressure/read.go @@ -23,7 +23,7 @@ var readPressureCmd = &cobra.Command{ Run: func(cmd *cobra.Command, args []string) { // read configuration - cnf, err := config.Read(configFile) + cnf, err := config.Read(*configFile) if err != nil { log.Fatalln(err) } diff --git a/cmd/rgbled/add.go b/cmd/rgbled/add.go index 2c07f50..0ed6dd9 100644 --- a/cmd/rgbled/add.go +++ b/cmd/rgbled/add.go @@ -21,7 +21,7 @@ var addRgbLedCmd = &cobra.Command{ flucky rgb-led add my-led GPIO13 GPIO17 GPIO26`), Run: func(cmd *cobra.Command, args []string) { // read configuration - cnf, err := config.Read(configFile) + cnf, err := config.Read(*configFile) if err != nil { log.Fatalln(err) } @@ -62,7 +62,7 @@ flucky rgb-led add my-led GPIO13 GPIO17 GPIO26`), } // save new configuration - err = config.Write(cnf, configFile) + err = config.Write(cnf, *configFile) if err != nil { log.Fatalln(err) } diff --git a/cmd/rgbled/disable.go b/cmd/rgbled/disable.go index 75ad8f7..d94b29b 100644 --- a/cmd/rgbled/disable.go +++ b/cmd/rgbled/disable.go @@ -17,7 +17,7 @@ flucky rgb-led disable 9f8abfc5-91f3-480c-a42d-b990b6f89e5d`, Run: func(cmd *cobra.Command, args []string) { // read configuration - cnf, err := config.Read(configFile) + cnf, err := config.Read(*configFile) if err != nil { log.Fatalln(err) } @@ -29,7 +29,7 @@ flucky rgb-led disable 9f8abfc5-91f3-480c-a42d-b990b6f89e5d`, } // save new configuration - err = config.Write(cnf, configFile) + err = config.Write(cnf, *configFile) if err != nil { log.Fatalln(err) } diff --git a/cmd/rgbled/enable.go b/cmd/rgbled/enable.go index 8c60d8c..40b2540 100644 --- a/cmd/rgbled/enable.go +++ b/cmd/rgbled/enable.go @@ -17,7 +17,7 @@ flucky rgb-led enable 9f8abfc5-91f3-480c-a42d-b990b6f89e5d`, Run: func(cmd *cobra.Command, args []string) { // read configuration - cnf, err := config.Read(configFile) + cnf, err := config.Read(*configFile) if err != nil { log.Fatalln(err) } @@ -29,7 +29,7 @@ flucky rgb-led enable 9f8abfc5-91f3-480c-a42d-b990b6f89e5d`, } // save new configuration - err = config.Write(cnf, configFile) + err = config.Write(cnf, *configFile) if err != nil { log.Fatalln(err) } diff --git a/cmd/rgbled/list.go b/cmd/rgbled/list.go index c7fa1f9..0fe4a7f 100644 --- a/cmd/rgbled/list.go +++ b/cmd/rgbled/list.go @@ -15,7 +15,7 @@ var listRgbLedCmd = &cobra.Command{ Aliases: []string{"ls"}, Run: func(cmd *cobra.Command, args []string) { // read configuration - cnf, err := config.Read(configFile) + cnf, err := config.Read(*configFile) if err != nil { log.Fatalln(err) } diff --git a/cmd/rgbled/off.go b/cmd/rgbled/off.go index f35db1b..6002b73 100644 --- a/cmd/rgbled/off.go +++ b/cmd/rgbled/off.go @@ -16,7 +16,7 @@ var offRgbLedCmd = &cobra.Command{ Run: func(cmd *cobra.Command, args []string) { // read configuration - cnf, err := config.Read(configFile) + cnf, err := config.Read(*configFile) if err != nil { log.Fatalln(err) } diff --git a/cmd/rgbled/on.go b/cmd/rgbled/on.go index 4c7a0e5..1bf471d 100644 --- a/cmd/rgbled/on.go +++ b/cmd/rgbled/on.go @@ -20,7 +20,7 @@ flucky rgb-led on 1c5b9424-f6e9-4a37-be5c-77e531e94aab red`, Run: func(cmd *cobra.Command, args []string) { // read configuration - cnf, err := config.Read(configFile) + cnf, err := config.Read(*configFile) if err != nil { log.Fatalln(err) } diff --git a/cmd/rgbled/remove.go b/cmd/rgbled/remove.go index 6afd513..174f024 100644 --- a/cmd/rgbled/remove.go +++ b/cmd/rgbled/remove.go @@ -17,7 +17,7 @@ flucky rgb-led remove 9f8abfc5-91f3-480c-a42d-b990b6f89e5d`, Args: cobra.ExactArgs(1), Run: func(cmd *cobra.Command, args []string) { // read configuration - cnf, err := config.Read(configFile) + cnf, err := config.Read(*configFile) if err != nil { log.Fatalln(err) } @@ -29,7 +29,7 @@ flucky rgb-led remove 9f8abfc5-91f3-480c-a42d-b990b6f89e5d`, } // save new configuration - err = config.Write(cnf, configFile) + err = config.Write(cnf, *configFile) if err != nil { log.Fatalln(err) } diff --git a/cmd/rgbled/rename.go b/cmd/rgbled/rename.go index 3dfa29d..299f653 100644 --- a/cmd/rgbled/rename.go +++ b/cmd/rgbled/rename.go @@ -16,7 +16,7 @@ flucky rgb-led disable my-led my-sweet-led flucky rgb-led disable 9f8abfc5-91f3-480c-a42d-b990b6f89e5d my-sweet-led`, Run: func(cmd *cobra.Command, args []string) { // read configuration - cnf, err := config.Read(configFile) + cnf, err := config.Read(*configFile) if err != nil { log.Fatalln(err) } @@ -28,7 +28,7 @@ flucky rgb-led disable 9f8abfc5-91f3-480c-a42d-b990b6f89e5d my-sweet-led`, } // save new configuration - err = config.Write(cnf, configFile) + err = config.Write(cnf, *configFile) if err != nil { log.Fatalln(err) } diff --git a/cmd/rgbled/rgbled.go b/cmd/rgbled/rgbled.go index b5bb5be..340797e 100644 --- a/cmd/rgbled/rgbled.go +++ b/cmd/rgbled/rgbled.go @@ -4,7 +4,7 @@ import ( "github.com/spf13/cobra" ) -var configFile string +var configFile *string var rgbLedCmd = &cobra.Command{ Use: "rgb-led", @@ -12,7 +12,7 @@ var rgbLedCmd = &cobra.Command{ } // InitCmd da -func InitCmd(cmd *cobra.Command, cnfFile string) { +func InitCmd(cmd *cobra.Command, cnfFile *string) { configFile = cnfFile cmd.AddCommand(rgbLedCmd) diff --git a/cmd/sensor/add.go b/cmd/sensor/add.go index 7ff1bf1..491a09e 100644 --- a/cmd/sensor/add.go +++ b/cmd/sensor/add.go @@ -25,7 +25,7 @@ flucky sensor add --wire-id 28-011432f0bb3d outdoor DS18B20 flucky sensor add --i2c-bus 1 --i2c-address 0x76 wetter-station BME280`, Run: func(cmd *cobra.Command, args []string) { // read configuration - cnf, err := config.Read(configFile) + cnf, err := config.Read(*configFile) if err != nil { log.Fatalln(err) } @@ -80,7 +80,7 @@ flucky sensor add --i2c-bus 1 --i2c-address 0x76 wetter-station BME280`, } // save new configuration - err = config.Write(cnf, configFile) + err = config.Write(cnf, *configFile) if err != nil { log.Fatalln(err) } diff --git a/cmd/sensor/disable.go b/cmd/sensor/disable.go index 7076ee2..585562e 100644 --- a/cmd/sensor/disable.go +++ b/cmd/sensor/disable.go @@ -15,7 +15,7 @@ var disableSensorCmd = &cobra.Command{ Run: func(cmd *cobra.Command, args []string) { // read configuration - cnf, err := config.Read(configFile) + cnf, err := config.Read(*configFile) if err != nil { log.Fatalln(err) } @@ -27,7 +27,7 @@ var disableSensorCmd = &cobra.Command{ } // save new configuration - err = config.Write(cnf, configFile) + err = config.Write(cnf, *configFile) if err != nil { log.Fatalln(err) } diff --git a/cmd/sensor/enable.go b/cmd/sensor/enable.go index 27ee865..971995f 100644 --- a/cmd/sensor/enable.go +++ b/cmd/sensor/enable.go @@ -15,7 +15,7 @@ var enableSensorCmd = &cobra.Command{ Run: func(cmd *cobra.Command, args []string) { // read configuration - cnf, err := config.Read(configFile) + cnf, err := config.Read(*configFile) if err != nil { log.Fatalln(err) } @@ -27,7 +27,7 @@ var enableSensorCmd = &cobra.Command{ } // save new configuration - err = config.Write(cnf, configFile) + err = config.Write(cnf, *configFile) if err != nil { log.Fatalln(err) } diff --git a/cmd/sensor/list.go b/cmd/sensor/list.go index 5bab7f8..8120e2f 100644 --- a/cmd/sensor/list.go +++ b/cmd/sensor/list.go @@ -15,7 +15,7 @@ var listSensorCmd = &cobra.Command{ Aliases: []string{"ls"}, Run: func(cmd *cobra.Command, args []string) { // read configuration - cnf, err := config.Read(configFile) + cnf, err := config.Read(*configFile) if err != nil { log.Fatalln(err) } @@ -27,7 +27,7 @@ var listSensorCmd = &cobra.Command{ } // save new configuration - err = config.Write(cnf, configFile) + err = config.Write(cnf, *configFile) if err != nil { log.Fatalln(err) } diff --git a/cmd/sensor/remove.go b/cmd/sensor/remove.go index f249563..9f9bbeb 100644 --- a/cmd/sensor/remove.go +++ b/cmd/sensor/remove.go @@ -15,7 +15,7 @@ var rmSensorCmd = &cobra.Command{ Args: cobra.ExactArgs(1), Run: func(cmd *cobra.Command, args []string) { // read configuration - cnf, err := config.Read(configFile) + cnf, err := config.Read(*configFile) if err != nil { log.Fatalln(err) } @@ -27,7 +27,7 @@ var rmSensorCmd = &cobra.Command{ } // save new configuration - err = config.Write(cnf, configFile) + err = config.Write(cnf, *configFile) if err != nil { log.Fatalln(err) } diff --git a/cmd/sensor/rename.go b/cmd/sensor/rename.go index 1dc0a30..51fdd07 100644 --- a/cmd/sensor/rename.go +++ b/cmd/sensor/rename.go @@ -15,7 +15,7 @@ var renameSensorCmd = &cobra.Command{ Example: fmt.Sprintf("flucky sensor rename indoor outdoor\nflucky sensor rename f98b00ea-a9b2-4e00-924f-113859d0af2d outdoor"), Run: func(cmd *cobra.Command, args []string) { // read configuration - cnf, err := config.Read(configFile) + cnf, err := config.Read(*configFile) if err != nil { log.Fatalln(err) } @@ -27,7 +27,7 @@ var renameSensorCmd = &cobra.Command{ } // save new configuration - err = config.Write(cnf, configFile) + err = config.Write(cnf, *configFile) if err != nil { log.Fatalln(err) } diff --git a/cmd/sensor/sensor.go b/cmd/sensor/sensor.go index 3c22105..cb2c87a 100644 --- a/cmd/sensor/sensor.go +++ b/cmd/sensor/sensor.go @@ -4,7 +4,7 @@ import ( "github.com/spf13/cobra" ) -var configFile string +var configFile *string var sensorCmd = &cobra.Command{ Use: "sensor", @@ -12,7 +12,7 @@ var sensorCmd = &cobra.Command{ } // InitCmd da -func InitCmd(cmd *cobra.Command, cnfFile string) { +func InitCmd(cmd *cobra.Command, cnfFile *string) { configFile = cnfFile cmd.AddCommand(sensorCmd) diff --git a/cmd/temperature/list.go b/cmd/temperature/list.go index c474f79..36e700a 100644 --- a/cmd/temperature/list.go +++ b/cmd/temperature/list.go @@ -21,7 +21,7 @@ var listTemperatureCmd = &cobra.Command{ Run: func(cmd *cobra.Command, args []string) { // read configuration - cnf, err := config.Read(configFile) + cnf, err := config.Read(*configFile) if err != nil { log.Fatalln(err) } diff --git a/cmd/temperature/read.go b/cmd/temperature/read.go index 9d05ae3..6e905ad 100644 --- a/cmd/temperature/read.go +++ b/cmd/temperature/read.go @@ -25,7 +25,7 @@ var readTemperatureCmd = &cobra.Command{ Run: func(cmd *cobra.Command, args []string) { // read configuration - cnf, err := config.Read(configFile) + cnf, err := config.Read(*configFile) if err != nil { log.Fatalln(err) } diff --git a/cmd/temperature/temperature.go b/cmd/temperature/temperature.go index 486770b..9417ba0 100644 --- a/cmd/temperature/temperature.go +++ b/cmd/temperature/temperature.go @@ -7,7 +7,7 @@ import ( ) var compression bool -var configFile string +var configFile *string var round float64 var temperatureCmd = &cobra.Command{ @@ -17,7 +17,7 @@ var temperatureCmd = &cobra.Command{ } // Execute a -func InitCmd(cmd *cobra.Command, cnfFile string) { +func InitCmd(cmd *cobra.Command, cnfFile *string) { configFile = cnfFile cmd.AddCommand(temperatureCmd)