change: get adb devices in cli

This commit is contained in:
lilong.129
2025-02-07 16:20:07 +08:00
parent ae5a137353
commit b314a2024c
3 changed files with 27 additions and 33 deletions

View File

@@ -1,29 +1,26 @@
package adb
import (
"fmt"
"github.com/spf13/cobra"
"github.com/httprunner/httprunner/v5/pkg/gadb"
"github.com/httprunner/httprunner/v5/pkg/uixt"
"github.com/httprunner/httprunner/v5/pkg/uixt/option"
)
var serial string
var androidRootCmd = &cobra.Command{
Use: "adb",
Short: "simple utils for android device management",
PersistentPreRun: func(cmd *cobra.Command, args []string) {},
}
func getDevice(serial string) (*gadb.Device, error) {
devices, err := uixt.GetAndroidDevices(serial)
func getDevice(serial string) (*uixt.AndroidDevice, error) {
device, err := uixt.NewAndroidDevice(option.WithSerialNumber(serial))
if err != nil {
return nil, err
}
if len(devices) > 1 {
return nil, fmt.Errorf("found multiple attached devices, please specify android serial")
}
return devices[0], nil
return device, nil
}
func Init(rootCmd *cobra.Command) {