forked from home-assistant/cli
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathapps_update.go
More file actions
75 lines (61 loc) · 1.72 KB
/
apps_update.go
File metadata and controls
75 lines (61 loc) · 1.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package cmd
import (
"log/slog"
helper "github.com/home-assistant/cli/client"
"github.com/spf13/cobra"
)
var appsUpdateCmd = &cobra.Command{
Use: "update [slug]",
Aliases: []string{"upgrade", "up"},
Short: "Upgrades a Home Assistant app to the latest version",
Long: `
This command can upgrade a Home Assistant app to its latest version.
It is currently not possible to upgrade/downgrade to a specific version.
`,
Example: `
ha apps update core_ssh
`,
ValidArgsFunction: appsCompletions,
Args: cobra.ExactArgs(1),
Run: func(cmd *cobra.Command, args []string) {
slog.Debug("apps update", "args", args)
section := "addons"
command := "{slug}/update"
url, err := helper.URLHelper(section, command)
if err != nil {
helper.PrintError(err)
ExitWithError = true
return
}
ProgressSpinner.Start()
request := helper.GetJSONRequestTimeout(helper.ContainerDownloadTimeout)
ProgressSpinner.Stop()
slug := args[0]
request.SetPathParams(map[string]string{
"slug": slug,
})
options := make(map[string]any)
backup, _ := cmd.Flags().GetBool("backup")
if cmd.Flags().Changed("backup") {
request.SetBody(options)
options["backup"] = backup
}
if len(options) > 0 {
slog.Debug("Request body", "options", options)
request.SetBody(options)
}
resp, err := request.Post(url)
resp, err = helper.GenericJSONErrorHandling(resp, err)
if err != nil {
helper.PrintError(err)
ExitWithError = true
} else {
ExitWithError = !helper.ShowJSONResponse(resp)
}
},
}
func init() {
appsUpdateCmd.Flags().Bool("backup", false, "Create partial backup before update")
appsUpdateCmd.RegisterFlagCompletionFunc("backup", boolCompletions)
appsCmd.AddCommand(appsUpdateCmd)
}