cli/cmd/multicast_update.go

54 lines
1.3 KiB
Go

package cmd
import (
"fmt"
helper "github.com/home-assistant/cli/client"
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"github.com/spf13/viper"
)
var multicastUpdateCmd = &cobra.Command{
Use: "update",
Aliases: []string{"upgrade", "downgrade", "up", "down"},
Short: "Updates the internal Home Assistant Multicast server",
Long: `
Using this command you can upgrade or downgrade the internal Home Assistant
Multicast server, to the latest version or the version specified.
`,
Example: `
ha multicast update --version 5
`,
Run: func(cmd *cobra.Command, args []string) {
log.WithField("args", args).Debug("multicast update")
section := "multicast"
command := "update"
base := viper.GetString("endpoint")
var options map[string]interface{}
version, _ := cmd.Flags().GetString("version")
if version != "" {
options = map[string]interface{}{"version": version}
}
ProgressSpinner.Start()
resp, err := helper.GenericJSONPost(base, section, command, options)
ProgressSpinner.Stop()
if err != nil {
fmt.Println(err)
ExitWithError = true
} else {
ExitWithError = !helper.ShowJSONResponse(resp)
}
},
}
func init() {
multicastUpdateCmd.Flags().StringP("version", "", "", "Version to update to")
multicastCmd.AddCommand(multicastUpdateCmd)
}