feat: print ios apps

This commit is contained in:
debugtalk
2022-10-01 18:28:47 +08:00
parent 51ed654ee2
commit ac1afdc87a
3 changed files with 91 additions and 41 deletions
+12 -29
View File
@@ -4,22 +4,14 @@ import (
"encoding/json"
"fmt"
"os"
"strings"
giDevice "github.com/electricbubble/gidevice"
"github.com/pkg/errors"
"github.com/spf13/cobra"
"github.com/httprunner/httprunner/v4/hrp/internal/uixt"
)
func wrapError(err error, msg string) error {
if strings.HasSuffix(err.Error(), "InvalidService") {
msg += ", check if Developer Disk Image mounted"
}
return errors.Wrap(err, msg)
}
type DeviceList []Device
type Device struct {
d giDevice.Device
UDID string `json:"UDID"`
@@ -77,30 +69,21 @@ var listIOSDevicesCmd = &cobra.Command{
Use: "devices",
Short: "List all iOS devices",
RunE: func(cmd *cobra.Command, args []string) error {
usbmux, err := giDevice.NewUsbmux()
devices, err := uixt.IOSDevices(udid)
if err != nil {
return wrapError(err, "create usbmux failed")
return err
}
devices, err := usbmux.Devices()
if err != nil {
return wrapError(err, "list ios devices failed")
}
var deviceList []giDevice.Device
// filter by udid
for _, d := range devices {
if udid != "" && udid != d.Properties().SerialNumber {
continue
if len(devices) == 0 {
if udid != "" {
fmt.Printf("no ios device found for udid: %s\n", udid)
os.Exit(1)
} else {
fmt.Println("no ios device found")
os.Exit(0)
}
deviceList = append(deviceList, d)
}
if udid != "" && len(deviceList) == 0 {
fmt.Printf("no ios device found for udid: %s\n", udid)
os.Exit(1)
}
for _, d := range deviceList {
for _, d := range devices {
deviceByte, _ := json.Marshal(d.Properties())
device := &Device{
d: d,