mirror of
https://github.com/httprunner/httprunner.git
synced 2026-06-11 02:39:46 +08:00
refactor: move hrp/ to root folder
This commit is contained in:
77
cmd/ios/mount.go
Normal file
77
cmd/ios/mount.go
Normal file
@@ -0,0 +1,77 @@
|
||||
package ios
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/rs/zerolog/log"
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
"github.com/httprunner/httprunner/v5/internal/builtin"
|
||||
"github.com/httprunner/httprunner/v5/internal/sdk"
|
||||
)
|
||||
|
||||
// mountCmd represents the mount command
|
||||
var mountCmd = &cobra.Command{
|
||||
Use: "mount",
|
||||
Short: "A brief description of your command",
|
||||
RunE: func(cmd *cobra.Command, args []string) (err error) {
|
||||
startTime := time.Now()
|
||||
defer func() {
|
||||
sdk.SendGA4Event("hrp_ios_mount", map[string]interface{}{
|
||||
"args": strings.Join(args, "-"),
|
||||
"success": err == nil,
|
||||
"engagement_time_msec": time.Since(startTime).Milliseconds(),
|
||||
})
|
||||
}()
|
||||
|
||||
device, err := getDevice(udid)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
images, errImage := device.ListImages()
|
||||
if err != nil {
|
||||
return fmt.Errorf("list device images failed: %v", err)
|
||||
}
|
||||
if listDeveloperDiskImage {
|
||||
for i, imgSign := range images {
|
||||
fmt.Printf("[%d] %s\n", i+1, imgSign)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
if errImage == nil && len(images) > 0 {
|
||||
log.Info().Strs("images", images).Msg("ios developer image is already mounted")
|
||||
return nil
|
||||
}
|
||||
|
||||
log.Info().Str("dir", developerDiskImageDir).Msg("start to mount ios developer image")
|
||||
|
||||
if !builtin.IsFolderPathExists(developerDiskImageDir) {
|
||||
return fmt.Errorf("developer disk image directory not exist: %s", developerDiskImageDir)
|
||||
}
|
||||
|
||||
if err = device.AutoMountImage(developerDiskImageDir); err != nil {
|
||||
return fmt.Errorf("mount developer disk image failed: %s", err)
|
||||
}
|
||||
|
||||
log.Info().Msg("mount developer disk image successfully")
|
||||
return nil
|
||||
},
|
||||
}
|
||||
|
||||
const defaultDeveloperDiskImageDir = "/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/DeviceSupport/"
|
||||
|
||||
var (
|
||||
developerDiskImageDir string
|
||||
listDeveloperDiskImage bool
|
||||
)
|
||||
|
||||
func init() {
|
||||
mountCmd.Flags().BoolVar(&listDeveloperDiskImage, "list", false, "list developer disk images")
|
||||
mountCmd.Flags().StringVarP(&developerDiskImageDir, "dir", "d", defaultDeveloperDiskImageDir, "specify developer disk image directory")
|
||||
mountCmd.Flags().StringVarP(&udid, "udid", "u", "", "specify device by udid")
|
||||
iosRootCmd.AddCommand(mountCmd)
|
||||
}
|
||||
Reference in New Issue
Block a user