-
Notifications
You must be signed in to change notification settings - Fork 4
/
pls.go
153 lines (145 loc) · 3.56 KB
/
pls.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
package main
import (
"os"
"github.com/hinshun/pls/command/dindcmd"
"github.com/hinshun/pls/command/mitmcmd"
"github.com/hinshun/pls/command/rethinkdbcmd"
"github.com/hinshun/pls/command/ucpcmd"
"github.com/hinshun/pls/docker/dind"
"gopkg.in/urfave/cli.v2"
)
func main() {
app := &cli.App{
Name: "pls",
Usage: "pretty please",
Commands: []*cli.Command{
{
Name: "ucp",
Usage: "Manage UCP",
Subcommands: []*cli.Command{
{
Name: "passwd",
Usage: "Change the admin username and password",
Flags: []cli.Flag{
&cli.StringFlag{
Name: "ssh",
Usage: "The SSH hostname of a UCP manager to perform passwd over SSH",
},
&cli.StringSliceFlag{
Name: "ssh-keypath",
Usage: "Specify a path to a private key to be used to authenticate the SSH connection",
},
},
Action: WrapAction(ucpcmd.Passwd),
},
},
},
{
Name: "dind",
Usage: "Manage Docker in Docker containers",
Subcommands: []*cli.Command{
{
Name: "create",
Usage: "Create a new dind container",
Flags: []cli.Flag{
&cli.StringFlag{
Name: "name",
Usage: "Assign a name to the container",
},
&cli.StringFlag{
Name: "image",
Usage: "The image to run Docker in Docker",
Value: dind.DindImageName,
},
&cli.StringFlag{
Name: "mitm",
Usage: "Proxy outgoing dockerd traffic to mitmproxy",
},
&cli.StringFlag{
Name: "registry",
Usage: "The server address of a Docker Registry to trust",
Value: dind.DefaultRegistryServerAddress,
},
&cli.StringFlag{
Name: "username",
Usage: "The username to authenticate against the Docker Registry",
},
&cli.StringFlag{
Name: "password",
Usage: "The password to authenticate against the Docker Registry",
},
},
Action: WrapAction(dindcmd.CreateDind),
},
{
Name: "list",
Aliases: []string{"ls"},
Usage: "List dind containers",
Action: WrapAction(dindcmd.ListDinds),
},
{
Name: "prune",
Usage: "Remove all dind containers",
Action: WrapAction(dindcmd.PruneDinds),
},
},
},
{
Name: "mitm",
Usage: "Manage mitmproxy (Man-in-the-Middle) containers",
Subcommands: []*cli.Command{
{
Name: "create",
Usage: "Create a new mitmproxy container",
Flags: []cli.Flag{
&cli.StringFlag{
Name: "name",
Usage: "Assign a name to the container",
},
},
Action: WrapAction(mitmcmd.CreateMITMProxy),
},
{
Name: "list",
Aliases: []string{"ls"},
Usage: "List mitmproxy containers",
Action: WrapAction(mitmcmd.ListMITMProxies),
},
{
Name: "prune",
Usage: "Remove all mitmproxy containers",
Action: WrapAction(mitmcmd.PruneMITMProxies),
},
},
},
{
Name: "rethinkdb",
Usage: "Manage RethinkDB",
Subcommands: []*cli.Command{
{
Name: "repl",
Usage: "Creates a ReQL REPL to a RethinkDB",
Action: WrapAction(rethinkdbcmd.CreateRethinkdbREPL),
},
},
},
},
}
app.Run(os.Args)
}
func WrapAction(action cli.ActionFunc) cli.ActionFunc {
return func(c *cli.Context) error {
err := action(c)
if err != nil {
return err
}
return nil
}
}
// type cliError struct {
// err error
// }
// func (c cliError) Error() string {
// return c.err.Error()
// return stacktrace.RootCause(c.err).Error()
// }