-
Notifications
You must be signed in to change notification settings - Fork 83
/
cmd_connect.go
58 lines (42 loc) · 1.02 KB
/
cmd_connect.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
package main
import (
"bufio"
"fmt"
"os"
"os/exec"
"strings"
"github.com/DarthSim/overmind/v2/utils"
"github.com/urfave/cli"
)
type cmdConnectHandler struct {
dialer
ControlMode bool
}
func (h *cmdConnectHandler) Run(c *cli.Context) error {
if c.NArg() > 1 {
utils.Fatal("Specify a single name of process")
}
conn, err := h.Dial()
utils.FatalOnErr(err)
fmt.Fprintf(conn, "get-connection %s\n", c.Args().First())
response, err := bufio.NewReader(conn).ReadString('\n')
utils.FatalOnErr(err)
response = strings.TrimSpace(response)
if response == "" {
utils.Fatal(fmt.Sprintf("Unknown process name: %s", c.Args().First()))
}
parts := strings.Split(response, " ")
if len(parts) < 2 {
utils.Fatal("Invalid server response")
}
args := []string{"-L", parts[0], "attach", "-t", parts[1]}
if h.ControlMode {
args = append([]string{"-CC"}, args...)
}
cmd := exec.Command("tmux", args...)
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
cmd.Stdin = os.Stdin
utils.FatalOnErr(cmd.Run())
return nil
}