use viper to get value of debug flag

This commit is contained in:
jichangjun 2020-06-15 15:29:49 +08:00
parent 4ad2bc3fd7
commit c82e61dcfe
5 changed files with 9 additions and 18 deletions

View File

@ -46,11 +46,7 @@ goc build -- -ldflags "-extldflags -static" -tags="embed kodo"
Run: func(cmd *cobra.Command, args []string) { Run: func(cmd *cobra.Command, args []string) {
gocBuild := build.NewBuild(buildFlags, packages, buildOutput) gocBuild := build.NewBuild(buildFlags, packages, buildOutput)
// remove temporary directory if needed // remove temporary directory if needed
defer func() { defer gocBuild.Clean()
if !debugGoc {
gocBuild.Clean()
}
}()
// doCover with original buildFlags, with new GOPATH( tmp:original ) // doCover with original buildFlags, with new GOPATH( tmp:original )
// in the tmp directory // in the tmp directory
cover.Execute(buildFlags, gocBuild.NewGOPATH, gocBuild.TmpDir, mode, center) cover.Execute(buildFlags, gocBuild.NewGOPATH, gocBuild.TmpDir, mode, center)

View File

@ -43,11 +43,7 @@ goc build --buildflags="-ldflags '-extldflags -static' -tags='embed kodo'"
Run: func(cmd *cobra.Command, args []string) { Run: func(cmd *cobra.Command, args []string) {
gocBuild := build.NewInstall(buildFlags, packages) gocBuild := build.NewInstall(buildFlags, packages)
// remove temporary directory if needed // remove temporary directory if needed
defer func() { defer gocBuild.Clean()
if !debugGoc {
gocBuild.Clean()
}
}()
// doCover with original buildFlags, with new GOPATH( tmp:original ) // doCover with original buildFlags, with new GOPATH( tmp:original )
// in the tmp directory // in the tmp directory
cover.Execute(buildFlags, gocBuild.NewGOPATH, gocBuild.TmpDir, mode, center) cover.Execute(buildFlags, gocBuild.NewGOPATH, gocBuild.TmpDir, mode, center)

View File

@ -39,11 +39,7 @@ goc run .
gocBuild := build.NewBuild(buildFlags, packages, buildOutput) gocBuild := build.NewBuild(buildFlags, packages, buildOutput)
gocBuild.GoRunExecFlag = goRunExecFlag gocBuild.GoRunExecFlag = goRunExecFlag
gocBuild.GoRunArguments = goRunArguments gocBuild.GoRunArguments = goRunArguments
defer func() { defer gocBuild.Clean()
if !debugGoc {
gocBuild.Clean()
}
}()
// start goc server // start goc server
var l = newLocalListener() var l = newLocalListener()
go cover.GocServer(ioutil.Discard).RunListener(l) go cover.GocServer(ioutil.Discard).RunListener(l)

View File

@ -25,6 +25,7 @@ import (
"github.com/qiniu/goc/pkg/cover" "github.com/qiniu/goc/pkg/cover"
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
"github.com/spf13/viper"
) )
func (b *Build) MvProjectsToTmp() { func (b *Build) MvProjectsToTmp() {
@ -155,5 +156,8 @@ func (b *Build) findWhereToInstall() string {
// Clean clears up the temporary workspace // Clean clears up the temporary workspace
func (b *Build) Clean() error { func (b *Build) Clean() error {
return os.RemoveAll(b.TmpDir) if !viper.GetBool("debug") {
return os.RemoveAll(b.TmpDir)
}
return nil
} }

View File

@ -26,9 +26,8 @@ import (
"net/url" "net/url"
"os" "os"
log "github.com/sirupsen/logrus"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
log "github.com/sirupsen/logrus"
"golang.org/x/tools/cover" "golang.org/x/tools/cover"
"k8s.io/test-infra/gopherage/pkg/cov" "k8s.io/test-infra/gopherage/pkg/cov"
) )