PKGBUILD/cmd/sensor/enable.go

40 lines
690 B
Go
Raw Normal View History

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-02-24 21:46:36 +00:00
"git.cryptic.systems/fh-trier/go-flucky/pkg/config"
"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
fc, err := config.Read(cfg)
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
err = fc.EnableSensor(args[0])
if err != nil {
log.Fatalln(err)
}
// save new configuration
err = config.Write(fc, cfg)
if err != nil {
log.Fatalln(err)
}
},
}
func init() {
sensorCmd.AddCommand(enableSensorCmd)
}