-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
64 lines (58 loc) · 1.27 KB
/
main.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
59
60
61
62
63
64
package main
import (
"fmt"
"os"
"os/exec"
"path"
"strings"
)
func bin(name string) string {
dir := os.Getenv("TIUP_COMPONENT_INSTALL_DIR")
if len(dir) == 0 {
dir = path.Dir(os.Args[0])
}
return path.Join(dir, name)
}
func execute(bin string, args []string) error {
cmd := exec.Command(bin, args...)
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
cmd.Stdin = os.Stdin
return cmd.Run()
}
func run(args []string) error {
bench := args[0]
switch bench {
case "ch", "rawsql", "tpcc", "tpch":
return execute(bin("go-tpc"), append([]string{bench}, args[1:]...))
case "ycsb":
return execute(bin("go-ycsb"), args[1:])
default:
kind := "bench command"
if strings.HasPrefix(bench, "-") {
kind = "flags"
}
return fmt.Errorf("unknown %s: %s", kind, bench)
}
}
func help() {
msg := `Usage: tiup bench {ch/rawsql/tpcc/tpch/ycsb} [flags]`
if len(os.Getenv("TIUP_COMPONENT_INSTALL_DIR")) == 0 {
msg = strings.Replace(msg, "tiup bench", os.Args[0], 1)
}
fmt.Println(msg)
}
func main() {
if len(os.Args) == 1 || os.Args[1] == "-h" || os.Args[1] == "--help" {
help()
return
}
if err := run(os.Args[1:]); err != nil {
if execErr, ok := err.(*exec.ExitError); ok {
os.Exit(execErr.ExitCode())
}
help()
fmt.Fprintln(os.Stderr, err.Error())
os.Exit(1)
}
}