-
Notifications
You must be signed in to change notification settings - Fork 5
/
command_sshconfig.go
52 lines (45 loc) · 1.38 KB
/
command_sshconfig.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
package vagrant
// SSHConfigCommand specifies options and output from vagrant ssh-config
type SSHConfigCommand struct {
BaseCommand
MachineNameArgument
SSHConfigResponse
// Name of a specific host to get SSH config info for. If not set, info for
// all VMs will be pulled.
Host string
}
// SSHConfig will return connection information for connecting to a vagrant
// machine via ssh. After setting options as appropriate, you must call
// Run() or Start() followed by Wait() to execute. Output will be in Configs
// and any error will be in Error.
func (client *VagrantClient) SSHConfig() *SSHConfigCommand {
return &SSHConfigCommand{
BaseCommand: newBaseCommand(client),
SSHConfigResponse: newSSHConfigResponse(),
}
}
func (cmd *SSHConfigCommand) buildArguments() []string {
args := []string{}
if cmd.Host != "" {
args = append(args, "--host", cmd.Host)
}
return cmd.appendMachineName(args)
}
func (cmd *SSHConfigCommand) init() error {
args := cmd.buildArguments()
return cmd.BaseCommand.init(&cmd.SSHConfigResponse, "ssh-config", args...)
}
// Run the command
func (cmd *SSHConfigCommand) Run() error {
if err := cmd.Start(); err != nil {
return err
}
return cmd.Wait()
}
// Start the command. You must call Wait() to complete execution.
func (cmd *SSHConfigCommand) Start() error {
if err := cmd.init(); err != nil {
return err
}
return cmd.BaseCommand.Start()
}