refactor: get attached android/ios devices

This commit is contained in:
lilong.129
2023-04-14 15:26:16 +08:00
parent f77b454cf2
commit c97b84dd39
6 changed files with 70 additions and 79 deletions

View File

@@ -5,10 +5,8 @@ import (
"fmt"
"os"
"github.com/pkg/errors"
"github.com/spf13/cobra"
"github.com/httprunner/httprunner/v4/hrp/pkg/gadb"
"github.com/httprunner/httprunner/v4/hrp/pkg/uixt"
)
@@ -21,22 +19,10 @@ var listAndroidDevicesCmd = &cobra.Command{
Use: "devices",
Short: "List all Android devices",
RunE: func(cmd *cobra.Command, args []string) error {
devices, err := uixt.DeviceList()
deviceList, err := uixt.GetAndroidDevices(serial)
if err != nil {
return errors.Wrap(err, "list android devices failed")
}
var deviceList []*gadb.Device
// filter by serial
for _, d := range devices {
if serial != "" && serial != d.Serial() {
continue
}
deviceList = append(deviceList, d)
}
if serial != "" && len(deviceList) == 0 {
fmt.Printf("no android device found for serial: %s\n", serial)
os.Exit(1)
fmt.Println(err)
os.Exit(0)
}
for _, d := range deviceList {