add darwin os check

This commit is contained in:
c9s 2021-02-03 18:22:16 +08:00
parent 22a6f0c173
commit b3aa7e7511

View File

@ -9,6 +9,7 @@ import (
"os" "os"
"os/exec" "os/exec"
"path/filepath" "path/filepath"
"runtime"
"strings" "strings"
"syscall" "syscall"
"time" "time"
@ -56,8 +57,8 @@ var RunCmd = &cobra.Command{
RunE: run, RunE: run,
} }
func runSetup(basectx context.Context, userConfig *bbgo.Config, enableApiServer bool) error { func runSetup(baseCtx context.Context, userConfig *bbgo.Config, enableApiServer bool) error {
ctx, cancelTrading := context.WithCancel(basectx) ctx, cancelTrading := context.WithCancel(baseCtx)
defer cancelTrading() defer cancelTrading()
environ := bbgo.NewEnvironment() environ := bbgo.NewEnvironment()
@ -77,6 +78,14 @@ func runSetup(basectx context.Context, userConfig *bbgo.Config, enableApiServer
log.WithError(err).Errorf("server error") log.WithError(err).Errorf("server error")
} }
}() }()
if runtime.GOOS == "darwin" {
<-time.After(time.Second * 3)
cmd := exec.Command("open", "http://localhost:8080/setup")
if err := cmd.Start() ; err != nil {
log.WithError(err).Errorf("can not call open command to open the web page")
}
}
} }
cmdutil.WaitForSignal(ctx, syscall.SIGINT, syscall.SIGTERM) cmdutil.WaitForSignal(ctx, syscall.SIGINT, syscall.SIGTERM)