/
commands.go
212 lines (208 loc) · 4.48 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
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
package commands
import (
"log"
"os"
"path/filepath"
"github.com/moul/advanced-ssh-config/pkg/config"
"github.com/urfave/cli"
// . "github.com/moul/advanced-ssh-config/pkg/logger"
)
func init() {
ex, err := os.Executable()
if err != nil {
log.Fatal(err)
}
abspath, err := filepath.Abs(ex)
if err != nil {
log.Fatal(err)
}
config.SetASSHBinaryPath(abspath)
}
// Commands is the list of cli commands
var Commands = []cli.Command{
{
Name: "connect",
Usage: "Connect to host SSH socket, used by ProxyCommand",
Description: "Argument is a host.",
Action: cmdProxy,
Hidden: true,
Flags: []cli.Flag{
cli.BoolFlag{
Name: "no-rewrite",
Usage: "Do not automatically rewrite outdated configuration",
},
cli.IntFlag{
Name: "port, p",
Usage: "SSH destination port",
},
cli.BoolFlag{
Name: "dry-run",
Usage: "Only show how assh would connect but don't actually do it",
},
},
},
{
Name: "ping",
Usage: "Send packets to the SSH server and display statistics",
Action: cmdPing,
Flags: []cli.Flag{
cli.IntFlag{
Name: "port, p",
Usage: "SSH destination port",
},
cli.UintFlag{
Name: "count, c",
Usage: "Stop after sending 'count' packets",
},
cli.Float64Flag{
Name: "wait, i",
Usage: "Wait 'wait' seconds between sending each packet",
Value: 1,
},
cli.BoolFlag{
Name: "o",
Usage: "Exit successfully after receiving one reply packet",
},
cli.Float64Flag{
Name: "waittime, W",
Usage: "Time in seconds to wait for a reply for each packet sent",
Value: 1,
},
},
},
/*
{
Name: "info",
Usage: "Print the connection config for host",
Description: "Argument is a host.",
Action: cmdInfo,
},
*/
/*
{
Name: "init",
Usage: "Configure SSH to use assh",
Description: "Build a .ssh/config.advanced file based on .ssh/config and update .ssh/config to use assh as ProxyCommand.",
Action: cmdInit,
},
*/
/*
{
Name: "etc-hosts",
Usage: "Generate a /etc/hosts file with assh hosts",
Description: "Build a .ssh/config.advanced file based on .ssh/config and update .ssh/config to use assh as ProxyCommand.",
Action: cmdEtcHosts,
},
*/
{
Name: "info",
Usage: "Display system-wide information",
Action: cmdInfo,
},
{
Name: "config",
Usage: "Manage ssh and assh configuration",
Subcommands: []cli.Command{
{
Name: "build",
Usage: "Build .ssh/config",
Flags: []cli.Flag{
cli.BoolFlag{
Name: "no-automatic-rewrite",
Usage: "Disable automatic ~/.ssh/config file regeneration",
},
cli.BoolFlag{
Name: "expand, e",
Usage: "Expand all fields",
},
cli.BoolFlag{
Name: "ignore-known-hosts",
Usage: "Ignore known-hosts file",
},
},
Action: cmdBuild,
},
{
Name: "json",
Usage: "Returns the JSON output",
Action: cmdBuildJSON,
Flags: []cli.Flag{
cli.BoolFlag{
Name: "expand, e",
Usage: "Expand all fields",
},
},
},
{
Name: "list",
Usage: "List all hosts from assh config",
Action: cmdList,
Flags: []cli.Flag{
cli.BoolFlag{
Name: "expand, e",
Usage: "Expand all fields",
},
},
},
{
Name: "graphviz",
Usage: "Generate a Graphviz graph of the hosts",
Action: cmdGraphviz,
Flags: []cli.Flag{
cli.BoolFlag{
Name: "show-isolated-hosts",
Usage: "Show isolated hosts",
},
cli.BoolFlag{
Name: "no-resolve-wildcard",
Usage: "Do not resolve wildcards in Gateways",
},
cli.BoolFlag{
Name: "no-inheritance-links",
Usage: "Do not show inheritance links",
},
},
},
{
Name: "search",
Usage: "Search entries by given search text",
Action: cmdSearch,
},
},
},
{
Name: "sockets",
Usage: "Manage control sockets",
Subcommands: []cli.Command{
{
Name: "list",
Action: cmdCsList,
Usage: "List active control sockets",
},
{
Name: "flush",
Action: cmdCsFlush,
Usage: "Close control sockets",
},
{
Name: "master",
Action: cmdCsMaster,
Usage: "Open a master control socket",
},
},
},
// FIXME: tree
{
Name: "wrapper",
Usage: "Initialize assh, then run ssh/scp/rsync...",
Hidden: true,
Subcommands: []cli.Command{
{
Name: "ssh",
Action: cmdWrapper,
Usage: "Wrap ssh",
Flags: config.SSHFlags,
},
},
},
}