-
Notifications
You must be signed in to change notification settings - Fork 4
/
portusctl.go
195 lines (179 loc) · 5.38 KB
/
portusctl.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
185
186
187
188
189
190
191
192
193
194
195
// Copyright (C) 2017-2019 Miquel Sabaté Solà <[email protected]>
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
package main
import (
"fmt"
"gopkg.in/urfave/cli.v1"
)
func main() {
app := cli.NewApp()
app.Name = "portusctl"
app.Usage = "Client for your Portus instance"
app.UsageText = "portusctl <command> [arguments...]"
app.HideHelp = true
app.Version = versionString()
app.CommandNotFound = func(context *cli.Context, cmd string) {
fmt.Printf("Incorrect usage: command '%v' does not exist.\n\n", cmd)
cli.ShowAppHelp(context)
}
app.Flags = []cli.Flag{
cli.StringFlag{
Name: "server, s",
Usage: "The location where the Portus instance serves requests",
EnvVar: "PORTUSCTL_API_SERVER",
},
cli.StringFlag{
Name: "token, t",
Usage: "The authentication token of the user for the Portus REST API",
EnvVar: "PORTUSCTL_API_TOKEN",
},
cli.StringFlag{
Name: "user, u",
Usage: "The user of the Portus REST API",
EnvVar: "PORTUSCTL_API_USER",
},
cli.BoolFlag{
Name: "quiet, q",
Usage: "Prevent portusctl from outputting general information",
EnvVar: "PORTUSCTL_QUIET",
},
}
app.Commands = []cli.Command{
{
Name: "create",
Usage: "Create the given resource",
Action: resourceDecorator(create, postAction),
ArgsUsage: `<resource> [arguments...]
Where <resource> is the resource that you want to create.`,
},
{
Name: "bootstrap",
Usage: "Bootstrap your Portus instance",
Action: bootstrapCmd,
ArgsUsage: `[arguments...]
Creates the first administrator of your Portus instance and returns back an application token ready to be used.`,
Flags: []cli.Flag{
cli.StringFlag{
Name: "format, f",
Value: "default",
Usage: "The output format. Available options: default and json",
EnvVar: "PORTUSCTL_FORMAT",
},
},
},
{
Name: "delete",
Usage: "Delete the given resource",
Action: resourceDecorator(delete, deleteAction),
ArgsUsage: `<resource> [arguments...]
Where <resource> is the resource that you want to delete.`,
},
{
Name: "exec",
Usage: "Execute an arbitrary command on the environment of your Portus instance",
Action: execCmd,
ArgsUsage: `<command> [arguments...]
Where <command> is the command that you want to run on the environment of your
Portus instance. The successive arguments will be passed also to this command.`,
Flags: []cli.Flag{
cli.StringFlag{
Name: "local, l",
Value: defaultPath,
Usage: "The location on the current host of your Portus instance",
EnvVar: "PORTUSCTL_EXEC_LOCATION",
},
cli.BoolTFlag{
Name: "vendor, v",
Usage: "Use the local 'vendor' directory as the gem environment",
EnvVar: "PORTUSCTL_EXEC_VENDOR",
},
},
},
{
Name: "explain",
Usage: "Fetch the documentation of the available resources",
Action: explainAction,
ArgsUsage: `[resource]
Where <resource> is the resource that you want to fetch. If no resource is
given, then it will list all the available resources.`,
},
{
Name: "get",
Usage: "Fetches info for the given resource",
Action: resourceDecorator(get, getAction),
ArgsUsage: `<resource> [arguments...]
Where <resource> is the resource that you want to fetch.`,
Flags: []cli.Flag{
cli.StringFlag{
Name: "format, f",
Value: "default",
Usage: "The output format. Available options: default and json",
EnvVar: "PORTUSCTL_FORMAT",
},
},
},
{
Name: "health",
Usage: "Get health info from Portus",
Action: healthAction,
ArgsUsage: " ",
Flags: []cli.Flag{
cli.StringFlag{
Name: "format, f",
Value: "default",
Usage: "The output format. Available options: default and json",
EnvVar: "PORTUSCTL_FORMAT",
},
},
},
{
Name: "update",
Usage: "Update the given resource",
Action: resourceDecorator(update, putAction),
ArgsUsage: `<resource> [arguments...]
Where <resource> is the resource that you want to update.`,
},
{
Name: "validate",
Usage: "Validate the given resource",
Action: resourceDecorator(validate, validateAction),
ArgsUsage: `<resource> [arguments...]
Where <resource> is the resource that you want to validate.`,
Flags: []cli.Flag{
cli.StringFlag{
Name: "format, f",
Value: "default",
Usage: "The output format. Available options: default and json",
EnvVar: "PORTUSCTL_FORMAT",
},
},
},
{
Name: "version",
Usage: "Print the client and server version information",
Action: versionAction,
ArgsUsage: " ",
Flags: []cli.Flag{
cli.StringFlag{
Name: "format, f",
Value: "default",
Usage: "The output format. Available options: default and json",
EnvVar: "PORTUSCTL_FORMAT",
},
},
},
}
app.RunAndExitOnError()
}