-
Notifications
You must be signed in to change notification settings - Fork 81
/
cmd_echo.go
42 lines (29 loc) · 638 Bytes
/
cmd_echo.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
package main
import (
"fmt"
"os"
"os/signal"
"syscall"
"github.com/DarthSim/overmind/v2/utils"
"github.com/urfave/cli"
)
type cmdEchoHandler struct{ dialer }
func (h *cmdEchoHandler) Run(c *cli.Context) error {
if c.Args().Present() {
utils.Fatal("Echo doesn't accept any arguments")
}
conn, err := h.Dial()
utils.FatalOnErr(err)
stop := make(chan os.Signal, 1)
go func() {
utils.ScanLines(conn, func(b []byte) bool {
fmt.Fprintf(os.Stdout, "%s\n", b)
return true
})
stop <- syscall.SIGINT
}()
fmt.Fprintln(conn, "echo")
signal.Notify(stop, syscall.SIGINT, syscall.SIGTERM)
<-stop
return nil
}