From 3aa40f3aab9044f648d597d946861b45df786ec4 Mon Sep 17 00:00:00 2001 From: c9s Date: Mon, 26 Oct 2020 13:56:48 +0800 Subject: [PATCH] disable viper config for now --- pkg/cmd/root.go | 2 ++ pkg/cmd/run.go | 13 +++++++++---- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/pkg/cmd/root.go b/pkg/cmd/root.go index 13e1f135f..96e5906e3 100644 --- a/pkg/cmd/root.go +++ b/pkg/cmd/root.go @@ -53,6 +53,7 @@ func Execute() { viper.AutomaticEnv() // setup the config paths for looking up the config file + /* viper.AddConfigPath("config") viper.AddConfigPath("$HOME/.bbgo") viper.AddConfigPath("/etc/bbgo") @@ -65,6 +66,7 @@ func Execute() { if err != nil { log.WithError(err).Fatal("failed to load config file") } + */ // Once the flags are defined, we can bind config keys with flags. if err := viper.BindPFlags(RootCmd.PersistentFlags()); err != nil { diff --git a/pkg/cmd/run.go b/pkg/cmd/run.go index 40bbb1c76..e55095be8 100644 --- a/pkg/cmd/run.go +++ b/pkg/cmd/run.go @@ -204,22 +204,27 @@ func build(ctx context.Context, buildDir string, userConfig *config.Config, goOS return "", err } - buildEnvs := []string{"GOOS=" + goOS, "GOARCH=" + goArch} + buildEnvs := []string{ + "GOOS=" + goOS, + "GOARCH=" + goArch, + } + buildTarget := filepath.Join(cwd, buildDir) - log.Infof("building binary from %s...", buildTarget) + binary := fmt.Sprintf("bbgow-%s-%s", goOS, goArch) - if output != nil { + if output != nil && len(*output) > 0 { binary = *output } + log.Infof("building binary %s from %s...", binary, buildTarget) buildCmd := exec.CommandContext(ctx, "go", "build", "-tags", "wrapper", "-o", binary, buildTarget) buildCmd.Env = append(os.Environ(), buildEnvs...) buildCmd.Stdout = os.Stdout buildCmd.Stderr = os.Stderr if err := buildCmd.Run(); err != nil { - return "", err + return binary, err } return binary, nil