2018-11-28 17:07:20 +00:00
|
|
|
package sensor
|
|
|
|
|
2019-02-24 21:46:36 +00:00
|
|
|
import (
|
|
|
|
"log"
|
2018-11-28 17:07:20 +00:00
|
|
|
|
2019-06-15 13:58:41 +00:00
|
|
|
"github.com/go-flucky/flucky/pkg/config"
|
2019-02-24 21:46:36 +00:00
|
|
|
"github.com/spf13/cobra"
|
|
|
|
)
|
2018-11-28 17:07:20 +00:00
|
|
|
|
2019-02-24 21:46:36 +00:00
|
|
|
var enableSensorCmd = &cobra.Command{
|
|
|
|
Use: "enable",
|
|
|
|
Short: "Enable Sensor",
|
|
|
|
Example: "flucky sensor enable outdoor",
|
|
|
|
Args: cobra.ExactArgs(1),
|
|
|
|
Run: func(cmd *cobra.Command, args []string) {
|
2018-11-28 17:07:20 +00:00
|
|
|
|
2019-02-24 21:46:36 +00:00
|
|
|
// read configuration
|
2019-06-16 11:00:50 +00:00
|
|
|
cnf, err := config.Read(configFile)
|
2019-02-24 21:46:36 +00:00
|
|
|
if err != nil {
|
|
|
|
log.Fatalln(err)
|
|
|
|
}
|
2018-11-28 17:07:20 +00:00
|
|
|
|
2019-02-24 21:46:36 +00:00
|
|
|
// disable sensor entry to list
|
2019-06-16 11:00:50 +00:00
|
|
|
err = cnf.EnableSensor(args[0])
|
2019-02-24 21:46:36 +00:00
|
|
|
if err != nil {
|
|
|
|
log.Fatalln(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// save new configuration
|
2019-06-16 11:00:50 +00:00
|
|
|
err = config.Write(cnf, configFile)
|
2019-02-24 21:46:36 +00:00
|
|
|
if err != nil {
|
|
|
|
log.Fatalln(err)
|
|
|
|
}
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
sensorCmd.AddCommand(enableSensorCmd)
|
|
|
|
}
|