You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
61 lines
1.0 KiB
61 lines
1.0 KiB
5 years ago
|
package main
|
||
|
|
||
|
import (
|
||
|
"flag"
|
||
|
"os"
|
||
|
"os/exec"
|
||
|
"strings"
|
||
|
|
||
|
"github.com/bilibili/kratos/pkg/testing/lich"
|
||
|
)
|
||
|
|
||
|
var (
|
||
|
noDown bool
|
||
|
)
|
||
|
|
||
|
func init() {
|
||
|
flag.BoolVar(&noDown, "nodown", false, "containers are not recycled.")
|
||
|
}
|
||
|
|
||
|
func parseArgs() (flags map[string]string) {
|
||
|
flags = make(map[string]string)
|
||
|
for idx, arg := range os.Args {
|
||
|
if idx == 0 {
|
||
|
continue
|
||
|
}
|
||
|
if arg == "down" {
|
||
|
flags["down"] = ""
|
||
|
return
|
||
|
}
|
||
|
if cmds := os.Args[idx+1:]; arg == "run" {
|
||
|
flags["run"] = strings.Join(cmds, " ")
|
||
|
return
|
||
|
}
|
||
|
}
|
||
|
return
|
||
|
}
|
||
|
|
||
|
func main() {
|
||
|
flag.Parse()
|
||
|
flags := parseArgs()
|
||
|
if _, ok := flags["down"]; ok {
|
||
|
lich.Teardown()
|
||
|
return
|
||
|
}
|
||
|
if cmd, ok := flags["run"]; !ok || cmd == "" {
|
||
|
panic("Your need 'run' flag assign to be run commands.")
|
||
|
}
|
||
|
if err := lich.Setup(); err != nil {
|
||
|
panic(err)
|
||
|
}
|
||
|
if !noDown {
|
||
|
defer lich.Teardown()
|
||
|
}
|
||
|
cmds := strings.Split(flags["run"], " ")
|
||
|
cmd := exec.Command(cmds[0], cmds[1:]...)
|
||
|
cmd.Stdout, cmd.Stderr = os.Stdout, os.Stderr
|
||
|
if err := cmd.Run(); err != nil {
|
||
|
panic(err)
|
||
|
}
|
||
|
}
|