-
Notifications
You must be signed in to change notification settings - Fork 91
/
snapshots.go
77 lines (72 loc) · 1.74 KB
/
snapshots.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
68
69
70
71
72
73
74
75
76
77
package command
import (
"fmt"
"os"
"github.com/home-assistant/hassio-cli/command/helpers"
"github.com/urfave/cli"
)
// CmdSnapshots snapshot endpoints for hass.io
func CmdSnapshots(c *cli.Context) {
const HassioBasePath = "snapshots"
action := ""
endpoint := ""
serverOverride := ""
get := false
DebugEnabled := c.GlobalBool("debug")
helpers.DebugEnabled = DebugEnabled
Options := c.String("options")
RawJSON := c.Bool("rawjson")
Filter := c.String("filter")
SnapSlug := c.String("slug")
if c.NArg() > 0 {
action = c.Args()[0]
}
switch action {
case "list": // GET
get = true
case "info":
if SnapSlug == "" {
fmt.Fprintf(os.Stderr, "--slug is required. See '%s --help'.\n", c.App.Name)
os.Exit(11)
}
get = true
endpoint = SnapSlug + "/info"
case "reload": // POST
endpoint = action
case "new":
endpoint = "new/full"
if c.String("name") != "" {
if Options != "" {
Options += ","
}
Options += "name=" + c.String("name")
}
if c.String("password") != "" {
if Options != "" {
Options += ","
}
Options += "password=" + c.String("password")
}
case "restore":
if SnapSlug == "" {
fmt.Fprintf(os.Stderr, "--slug is required. See '%s --help'.\n", c.App.Name)
os.Exit(11)
}
if c.String("password") != "" {
Options = "password=" + c.String("password")
}
endpoint = SnapSlug + "/restore/full"
case "remove":
if SnapSlug == "" {
fmt.Fprintf(os.Stderr, "--slug is required. See '%s --help'.\n", c.App.Name)
os.Exit(11)
}
endpoint = SnapSlug + "/remove"
default:
fmt.Fprintf(os.Stderr, "No valid action detected.\n")
os.Exit(3)
}
if endpoint != "" || action == "list" {
helpers.ExecCommand(HassioBasePath, endpoint, serverOverride, get, Options, Filter, RawJSON)
}
}