feat: print ios apps

This commit is contained in:
debugtalk
2022-10-01 17:21:36 +08:00
parent 8c0d495c52
commit d96c599749
3 changed files with 91 additions and 41 deletions

53
hrp/cmd/ios/apps.go Normal file
View File

@@ -0,0 +1,53 @@
package ios
import (
"fmt"
"os"
"strings"
"github.com/pkg/errors"
"github.com/spf13/cobra"
"github.com/httprunner/httprunner/v4/hrp/internal/uixt"
)
var listIOSAppsCmd = &cobra.Command{
Use: "apps",
Short: "List all iOS installed apps",
RunE: func(cmd *cobra.Command, args []string) error {
devices, err := uixt.IOSDevices(udid)
if err != nil {
return err
}
if len(devices) == 0 {
fmt.Println("no ios device found")
os.Exit(1)
}
if len(devices) > 1 {
return fmt.Errorf("multiple devices found, please specify udid")
}
device := devices[0]
apps, err := device.AppList()
if err != nil {
return errors.Wrap(err, "get ios apps failed")
}
for _, app := range apps {
if appType != "all" && strings.ToLower(app.Type) != appType {
continue
}
fmt.Printf("%-10.10s %-30.30s %-50.50s %-s\n",
app.Type, app.DisplayName, app.CFBundleIdentifier, app.Version)
}
return nil
},
}
var appType string
func init() {
listIOSAppsCmd.Flags().StringVarP(&udid, "udid", "u", "", "filter by device's udid")
listIOSAppsCmd.Flags().StringVarP(&appType, "type", "t", "user", "filter application type [user|system|pluginkit|all]")
iosRootCmd.AddCommand(listIOSAppsCmd)
}

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,