forked from cloudfoundry/bosh-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
interactive.go
43 lines (32 loc) · 1007 Bytes
/
interactive.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
package ssh
import (
"os"
bosherr "github.com/cloudfoundry/bosh-utils/errors"
boshsys "github.com/cloudfoundry/bosh-utils/system"
boshdir "github.com/cloudfoundry/bosh-cli/director"
)
type InteractiveRunner struct {
comboRunner ComboRunner
}
func NewInteractiveRunner(comboRunner ComboRunner) InteractiveRunner {
return InteractiveRunner{comboRunner}
}
func (r InteractiveRunner) Run(connOpts ConnectionOpts, result boshdir.SSHResult, rawCmd []string) error {
if len(result.Hosts) != 1 {
return bosherr.Errorf("Interactive SSH only works for a single host at a time")
}
if len(rawCmd) != 0 {
return bosherr.Errorf("Interactive SSH does not accept commands")
}
cmdFactory := func(host boshdir.Host) boshsys.Command {
return boshsys.Command{
Name: "ssh",
Args: []string{printableHost{host}.String(), "-l", host.Username},
Stdin: os.Stdin,
Stdout: os.Stdout,
Stderr: os.Stderr,
KeepAttached: true,
}
}
return r.comboRunner.Run(connOpts, result, cmdFactory)
}