diff --git a/adbatch.exe b/adbatch.exe deleted file mode 100644 index fbc516f..0000000 Binary files a/adbatch.exe and /dev/null differ diff --git a/main.go b/main.go index 7b48146..3e98fc2 100644 --- a/main.go +++ b/main.go @@ -2,12 +2,10 @@ package main import ( "strings" - "fmt" "os" - "path/filepath" + "sync" "github.com/brunohgv/adbatch/adb" - "github.com/brunohgv/adbatch/utils" - "github.com/brunohgv/adbatch/files" + "github.com/brunohgv/adbatch/runner" ) func main() { @@ -16,17 +14,25 @@ func main() { command := strings.Join(arguments, " ") deviceIds := adb.GetDevices() - currentDir, err := os.Getwd() + outputDir, err := os.Getwd() if err != nil { panic("Could not locate the current directory") } + var wg sync.WaitGroup for _, deviceId := range deviceIds { - out, _ := utils.ExecuteCommand(fmt.Sprintf("adb -s %s %s", deviceId, command)) - fmt.Printf("Output for %v:\n\n", deviceId) - fmt.Println(out) - filePath := filepath.Join(currentDir, fmt.Sprintf("%v-out.txt", deviceId)) - files.WriteFile(filePath, out) - fmt.Println("================================================") + wg.Add(1) + + go func(deviceId string) { + defer wg.Done() + process := runner.Process{ + Command: command, + DeviceId: deviceId, + FilePath: outputDir, + } + process.Run() + }(deviceId) } + + wg.Wait() } \ No newline at end of file diff --git a/runner/runner.go b/runner/runner.go new file mode 100644 index 0000000..8c2d1eb --- /dev/null +++ b/runner/runner.go @@ -0,0 +1,23 @@ +package runner + +import ( + "fmt" + "path/filepath" + "github.com/brunohgv/adbatch/utils" + "github.com/brunohgv/adbatch/files" +) + +type Process struct { + Command string + DeviceId string + FilePath string +} + +func (p *Process) Run() { + out, _ := utils.ExecuteCommand(fmt.Sprintf("adb -s %s %s", p.DeviceId, p.Command)) + fmt.Printf("Output for %v:\n\n", p.DeviceId) + fmt.Println(out) + filePath := filepath.Join(p.FilePath, fmt.Sprintf("%v-out.txt", p.DeviceId)) + files.WriteFile(filePath, out) + fmt.Println("================================================") +} \ No newline at end of file