|
@@ -52,7 +52,7 @@ func GetRuntimeEnv(key string) (string, error) {
|
|
|
for _, envItem := range envStrings {
|
|
|
envItem = strings.TrimSuffix(envItem, "\r")
|
|
|
envKeyValue := strings.Split(envItem, "=")
|
|
|
- if strings.EqualFold(strings.TrimSpace(envKeyValue[0]), key) {
|
|
|
+ if len(envKeyValue) == 2 && strings.TrimSpace(envKeyValue[0]) == key {
|
|
|
runtimeEnv = strings.TrimSpace(envKeyValue[1])
|
|
|
}
|
|
|
}
|
|
@@ -79,31 +79,31 @@ func GetGOBIN() string {
|
|
|
return GOBIN
|
|
|
}
|
|
|
|
|
|
-func Run(binary string, args []string) (string, error) {
|
|
|
+func Run(binary string, args []string) ([]byte, error) {
|
|
|
cmd := exec.Command(binary, args...)
|
|
|
cmd.Env = append(cmd.Env, os.Environ()...)
|
|
|
output, cmdErr := cmd.CombinedOutput()
|
|
|
if cmdErr != nil {
|
|
|
- return "", cmdErr
|
|
|
+ return nil, cmdErr
|
|
|
}
|
|
|
- if len(output) > 0 {
|
|
|
- return string(output), nil
|
|
|
- }
|
|
|
- return "", nil
|
|
|
+ return output, nil
|
|
|
}
|
|
|
|
|
|
func RunMany(binary string, args, files []string) {
|
|
|
fmt.Println("Processing...")
|
|
|
+
|
|
|
+ maxTasks := make(chan struct{}, runtime.NumCPU())
|
|
|
for _, file := range files {
|
|
|
- args2 := append(args, file)
|
|
|
- output, err := Run(binary, args2)
|
|
|
- if err != nil {
|
|
|
- fmt.Println(err)
|
|
|
- continue
|
|
|
- }
|
|
|
- if len(output) > 0 {
|
|
|
- fmt.Println(output)
|
|
|
- }
|
|
|
+ maxTasks <- struct{}{}
|
|
|
+ go func(file string) {
|
|
|
+ output, err := Run(binary, append(args, file))
|
|
|
+ if err != nil {
|
|
|
+ fmt.Println(err)
|
|
|
+ } else if len(output) > 0 {
|
|
|
+ fmt.Println(string(output))
|
|
|
+ }
|
|
|
+ <-maxTasks
|
|
|
+ }(file)
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -135,7 +135,7 @@ func main() {
|
|
|
suffix = ".exe"
|
|
|
}
|
|
|
gofmt := "gofmt" + suffix
|
|
|
- goimports := "goimports" + suffix
|
|
|
+ goimports := "gci" + suffix
|
|
|
|
|
|
if gofmtPath, err := exec.LookPath(gofmt); err != nil {
|
|
|
fmt.Println("Can not find", gofmt, "in system path or current working directory.")
|
|
@@ -151,7 +151,7 @@ func main() {
|
|
|
goimports = goimportsPath
|
|
|
}
|
|
|
|
|
|
- rawFilesSlice := make([]string, 0)
|
|
|
+ rawFilesSlice := make([]string, 0, 1000)
|
|
|
walkErr := filepath.Walk(pwd, func(path string, info os.FileInfo, err error) error {
|
|
|
if err != nil {
|
|
|
fmt.Println(err)
|
|
@@ -166,7 +166,8 @@ func main() {
|
|
|
filename := filepath.Base(path)
|
|
|
if strings.HasSuffix(filename, ".go") &&
|
|
|
!strings.HasSuffix(filename, ".pb.go") &&
|
|
|
- !strings.Contains(dir, filepath.Join("testing", "mocks")) {
|
|
|
+ !strings.Contains(dir, filepath.Join("testing", "mocks")) &&
|
|
|
+ !strings.Contains(path, filepath.Join("main", "distro", "all", "all.go")) {
|
|
|
rawFilesSlice = append(rawFilesSlice, path)
|
|
|
}
|
|
|
|