forked from home-assistant/cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommands.go
184 lines (179 loc) · 4.57 KB
/
commands.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
package main
// https://github.com/home-assistant/hassio/blob/dev/API.md
import (
"fmt"
"os"
"github.com/home-assistant/hassio-cli/command"
"github.com/urfave/cli"
)
// GlobalFlags Used to hold global flags
var GlobalFlags = []cli.Flag{
cli.BoolFlag{
Name: "debug, d",
Usage: "Prints Debug information",
},
cli.StringFlag{
Name: "log-format",
Usage: "log format to use, valid options are text and json. Default is text",
},
}
// Commands holds the commands that are supported by the CLI
var Commands = []cli.Command{
{
Name: "homeassistant",
Aliases: []string{"ha"},
Usage: "info, logs, check, restart, start, stop, update",
Action: command.CmdHomeassistant,
Flags: []cli.Flag{
cli.BoolFlag{
Name: "rawjson, j",
Usage: "Returns the output in JSON format",
},
cli.StringFlag{
Name: "options, o",
Usage: "holds data for POST in format `key=val,key2=val2`",
},
cli.StringFlag{
Name: "filter, f",
Usage: "properties to extract from returned data `prop1,prop2`",
},
},
},
{
Name: "supervisor",
Usage: "info, logs, reload, update",
Aliases: []string{"su"},
Action: command.CmdSupervisor,
Flags: []cli.Flag{
cli.BoolFlag{
Name: "rawjson, j",
Usage: "Returns the output in JSON format",
},
cli.StringFlag{
Name: "options, o",
Usage: "holds data for POST in format `key=val,key2=val2`",
},
cli.StringFlag{
Name: "filter, f",
Usage: "properties to extract from returned data `prop1,prop2`",
},
},
},
{
Name: "host",
Usage: "reboot, shutdown",
Aliases: []string{"ho"},
Action: command.CmdHost,
Flags: []cli.Flag{
cli.BoolFlag{
Name: "rawjson, j",
Usage: "Returns the output in JSON format",
},
cli.StringFlag{
Name: "options, o",
Usage: "holds data for POST in format `key=val,key2=val2`",
},
cli.StringFlag{
Name: "filter, f",
Usage: "properties to extract from returned data `prop1,prop2`",
},
},
},
{
Name: "hassos",
Aliases: []string{"os"},
Usage: "info, update",
Action: command.CmdHassOS,
Flags: []cli.Flag{
cli.BoolFlag{
Name: "rawjson, j",
Usage: "Returns the output in JSON format",
},
cli.StringFlag{
Name: "options, o",
Usage: "holds data for POST in format `key=val,key2=val2`",
},
cli.StringFlag{
Name: "filter, f",
Usage: "properties to extract from returned data `prop1,prop2`",
},
},
},
{
Name: "hardware",
Usage: "info, audio",
Aliases: []string{"hw"},
Action: command.CmdHardware,
Flags: []cli.Flag{
cli.BoolFlag{
Name: "rawjson, j",
Usage: "Returns the output in JSON format",
},
cli.StringFlag{
Name: "filter, f",
Usage: "properties to extract from returned data `prop1,prop2`",
},
},
},
{
Name: "snapshots",
Usage: "list, info, reload, new, restore, remove",
Aliases: []string{"sn"},
Action: command.CmdSnapshots,
Flags: []cli.Flag{
cli.BoolFlag{
Name: "rawjson, j",
Usage: "Returns the output in JSON format",
},
cli.StringFlag{
Name: "options, o",
Usage: "holds data for POST in format `key=val,key2=val2`",
},
cli.StringFlag{
Name: "filter, f",
Usage: "properties to extract from returned data `prop1,prop2`",
},
cli.StringFlag{
Name: "slug",
Usage: "used with 'info|remove|restore|new' actions to return info on a specific snapshot `slugofsnapshot`",
},
cli.StringFlag{
Name: "name",
Usage: "used with 'restore|new' actions to set a name for a snapshot",
},
cli.StringFlag{
Name: "password",
Usage: "used with 'restore|new' actions to set a password on a snapshot",
},
},
},
{
Name: "addons",
Usage: "list, info, logo, changelog, logs, stats,\n reload, start, stop, install, uninstall, update",
Aliases: []string{"ad"},
Action: command.CmdAddons,
Flags: []cli.Flag{
cli.BoolFlag{
Name: "rawjson, j",
Usage: "Returns the output in JSON format",
},
cli.StringFlag{
Name: "options, o",
Usage: "holds data for POST in format `key=val,key2=val2`",
},
cli.StringFlag{
Name: "filter, f",
Usage: "properties to extract from returned data `prop1,prop2`",
},
cli.StringFlag{
Name: "name",
Usage: "used with 'info' actions to return info on a specific addon `nameofaddon`",
},
},
},
}
// CommandNotFound used to display if a user enters a non-existant command
func CommandNotFound(c *cli.Context, command string) {
fmt.Fprintf(os.Stderr, "%s: '%s' is not a %s command. See '%s --help'.\n", c.App.Name, command, c.App.Name, c.App.Name)
os.Exit(2)
}