-
Notifications
You must be signed in to change notification settings - Fork 91
/
addons.go
67 lines (62 loc) · 1.58 KB
/
addons.go
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
package command
import (
"fmt"
"os"
"github.com/home-assistant/hassio-cli/command/helpers"
"github.com/urfave/cli"
)
// CmdAddons All addon endpoints for hass.io
func CmdAddons(c *cli.Context) {
const HassioBasePath = "addons"
action := ""
endpoint := ""
serverOverride := ""
get := false
DebugEnabled := c.GlobalBool("debug")
helpers.DebugEnabled = DebugEnabled
Options := c.String("options")
RawJSON := c.Bool("rawjson")
Filter := c.String("filter")
AddonName := c.String("name")
if c.NArg() > 0 {
action = c.Args()[0]
}
switch action {
case "list": // GET
endpoint = ""
get = true
case "info",
"logo",
"changelog",
"logs", // Fix as not JSON format for output
"stats":
if AddonName == "" {
fmt.Fprintf(os.Stderr, "--name is required. See '%s --help'.\n", c.App.Name)
os.Exit(11)
}
endpoint = AddonName + "/" + action
get = true
case "reload": // POST
endpoint = action
case "start",
"stop",
"install",
"uninstall",
"update":
if AddonName == "" {
fmt.Fprintf(os.Stderr, "--name is required. See '%s --help'.\n", c.App.Name)
os.Exit(11)
}
endpoint = AddonName + "/" + action
default:
fmt.Fprintf(os.Stdout, "No valid action detected.\n")
os.Exit(3)
}
if DebugEnabled {
fmt.Fprintf(os.Stdout, "DEBUG [addons]: action->'%s', endpoint='%s', serverOverride->'%s', GET->'%t', options->'%s', rawjson->'%t', filter->'%s'\n",
action, endpoint, serverOverride, get, Options, RawJSON, Filter)
}
if endpoint != "" || action == "list" {
helpers.ExecCommand(HassioBasePath, endpoint, serverOverride, get, Options, Filter, RawJSON)
}
}