40 lines
785 B
Go
40 lines
785 B
Go
package sensor
|
|
|
|
import (
|
|
"fmt"
|
|
"log"
|
|
|
|
"github.com/go-flucky/flucky/pkg/config"
|
|
"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
|
|
cnf, err := config.Read(*configFile)
|
|
if err != nil {
|
|
log.Fatalln(err)
|
|
}
|
|
|
|
// rename sensor
|
|
err = cnf.RenameSensor(args[0], args[1])
|
|
if err != nil {
|
|
log.Println(err)
|
|
}
|
|
|
|
// save new configuration
|
|
err = config.Write(cnf, *configFile)
|
|
if err != nil {
|
|
log.Fatalln(err)
|
|
}
|
|
},
|
|
}
|
|
|
|
func init() {
|
|
sensorCmd.AddCommand(renameSensorCmd)
|
|
}
|