-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathmain.go
More file actions
50 lines (43 loc) · 817 Bytes
/
main.go
File metadata and controls
50 lines (43 loc) · 817 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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package main
import (
"fmt"
"io"
"os"
"os/signal"
"strings"
"syscall"
"github.com/disksing/region-dist-cli/cli"
)
func main() {
pdAddr := os.Getenv("PD_ADDR")
if pdAddr != "" {
os.Args = append(os.Args, "-u", pdAddr)
}
sc := make(chan os.Signal, 1)
signal.Notify(sc,
syscall.SIGHUP,
syscall.SIGINT,
syscall.SIGTERM,
syscall.SIGQUIT)
go func() {
sig := <-sc
fmt.Printf("\nGot signal [%v] to exit.\n", sig)
switch sig {
case syscall.SIGTERM:
os.Exit(0)
default:
os.Exit(1)
}
}()
var input []string
stat, _ := os.Stdin.Stat()
if (stat.Mode() & os.ModeCharDevice) == 0 {
b, err := io.ReadAll(os.Stdin)
if err != nil {
fmt.Println(err)
return
}
input = strings.Split(strings.TrimSpace(string(b[:])), " ")
}
cli.MainStart(append(os.Args[1:], input...))
}