-
Notifications
You must be signed in to change notification settings - Fork 53
Expand file tree
/
Copy pathcmd_ssh.go
More file actions
35 lines (28 loc) · 709 Bytes
/
cmd_ssh.go
File metadata and controls
35 lines (28 loc) · 709 Bytes
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
package main
import (
"os"
"os/exec"
"syscall"
"github.com/urfave/cli"
)
var sshCommand = cli.Command{
Name: "ssh",
Usage: "start an ssh session with your vm",
Description: "login to your virtual machine using ssh, this is a convenience shortcut",
Action: func(ctx *cli.Context) error {
currentUser := getUser()
cfg, err := readConfig(getPath(currentUser))
if err != nil {
return cli.NewExitError(err.Error(), 1)
}
bin, err := exec.LookPath("ssh")
if err != nil {
return cli.NewExitError(err.Error(), 1)
}
err = syscall.Exec(bin, []string{"ssh", cfg.Hostname}, os.Environ())
if err != nil {
return cli.NewExitError(err.Error(), 1)
}
return nil
},
}