2019-02-28 19:05:23 +00:00
|
|
|
package sensor
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"log"
|
|
|
|
|
2019-06-15 13:58:41 +00:00
|
|
|
"github.com/go-flucky/flucky/pkg/config"
|
2019-02-28 19:05:23 +00:00
|
|
|
"github.com/spf13/cobra"
|
|
|
|
)
|
|
|
|
|
|
|
|
var renameSensorCmd = &cobra.Command{
|
|
|
|
Use: "rename",
|
|
|
|
Short: "Rename Sensor",
|
|
|
|
Args: cobra.ExactArgs(2),
|
|
|
|
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
|
2019-08-19 10:24:08 +00:00
|
|
|
cnf, err := config.Read(*configFile)
|
2019-02-28 19:05:23 +00:00
|
|
|
if err != nil {
|
|
|
|
log.Fatalln(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// rename sensor
|
2019-06-16 11:00:50 +00:00
|
|
|
err = cnf.RenameSensor(args[0], args[1])
|
2019-02-28 19:05:23 +00:00
|
|
|
if err != nil {
|
|
|
|
log.Println(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// save new configuration
|
2019-08-19 10:24:08 +00:00
|
|
|
err = config.Write(cnf, *configFile)
|
2019-02-28 19:05:23 +00:00
|
|
|
if err != nil {
|
|
|
|
log.Fatalln(err)
|
|
|
|
}
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
sensorCmd.AddCommand(renameSensorCmd)
|
|
|
|
}
|