PKGBUILD/cmd/rgbled/rename.go

41 lines
821 B
Go

package rgbled
import (
"log"
"github.com/go-flucky/flucky/pkg/config"
"github.com/spf13/cobra"
)
var renameRgbLedCmd = &cobra.Command{
Use: "rename",
Short: "Rename a RGB-LED",
Args: cobra.ExactArgs(2),
Example: `flucky rgb-led disable <name/uuid> <new-name>
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)
if err != nil {
log.Fatalln(err)
}
// rename sensor
err = cnf.RenameRGBLED(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() {
rgbLedCmd.AddCommand(renameRgbLedCmd)
}