forked from home-assistant/cli
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathapps_stop.go
More file actions
58 lines (46 loc) · 1.15 KB
/
Copy pathapps_stop.go
File metadata and controls
58 lines (46 loc) · 1.15 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
package cmd
import (
"log/slog"
helper "github.com/home-assistant/cli/client"
"github.com/spf13/cobra"
)
var appsStopCmd = &cobra.Command{
Use: "stop [slug]",
Aliases: []string{"halt", "shutdown", "quit"},
Short: "Manually stop a running Home Assistant app",
Long: `
This command allows you to manually stop a Home Assistant app
`,
Example: `
ha apps stop core_ssh
`,
ValidArgsFunction: appsCompletions,
Args: cobra.ExactArgs(1),
Run: func(cmd *cobra.Command, args []string) {
slog.Debug("apps stop", "args", args)
section := "addons"
command := "{slug}/stop"
url, err := helper.URLHelper(section, command)
if err != nil {
helper.PrintError(err)
ExitWithError = true
return
}
request := helper.GetJSONRequestTimeout(helper.ContainerOperationTimeout)
slug := args[0]
request.SetPathParams(map[string]string{
"slug": slug,
})
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() {
appsCmd.AddCommand(appsStopCmd)
}