forked from danielpaulus/go-ios
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcmd_ui_download.go
More file actions
88 lines (81 loc) · 2.62 KB
/
Copy pathcmd_ui_download.go
File metadata and controls
88 lines (81 loc) · 2.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
package main
import (
"fmt"
"os"
"path/filepath"
"strings"
"time"
)
type uiDownloadResult struct {
Target string `json:"target"`
URL string `json:"url"`
ArtifactPath string `json:"artifactPath"`
ArtifactType string `json:"artifactType"`
SizeBytes int64 `json:"sizeBytes"`
AppPath string `json:"appPath,omitempty"`
}
func runUIDownloadCommand(ctx commandContext) {
targets := uiDownloadTargets(ctx)
outputDir, _ := ctx.Args.String("--output")
if outputDir == "" {
outputDir = "."
}
absOutputDir, err := filepath.Abs(outputDir)
exitIfError("failed resolving output dir", err)
exitIfError("failed creating output dir", os.MkdirAll(absOutputDir, 0755))
results := make([]uiDownloadResult, 0, len(targets))
for _, target := range targets {
results = append(results, downloadUIInstallTarget(target, absOutputDir))
}
fmt.Println(convertToJSONString(map[string]interface{}{
"outputDir": absOutputDir,
"downloaded": results,
}))
}
func uiDownloadTargets(ctx commandContext) []uiInstallTarget {
targets := []uiInstallTarget{
{
Name: "wda",
DefaultURL: defaultWDAArtifactURL,
DefaultBundle: defaultWDABundleID,
DefaultName: "go-ios WDA",
OutputBaseName: "WebDriverAgentRunner",
},
{
Name: "devicekit",
DefaultURL: defaultDeviceKitArtifactURL,
DefaultName: "go-ios DeviceKit",
OutputBaseName: "devicekit-ios-runner",
},
}
switch {
case boolArg(ctx.Args, "wda"):
return targets[:1]
case boolArg(ctx.Args, "devicekit"):
return targets[1:]
default:
return targets
}
}
func downloadUIInstallTarget(target uiInstallTarget, outputDir string) uiDownloadResult {
artifactPath := filepath.Join(outputDir, filepath.Base(target.DefaultURL))
exitIfError("failed downloading "+target.Name, downloadUIArtifact(target.DefaultURL, artifactPath))
info, err := os.Stat(artifactPath)
exitIfError("failed stat "+artifactPath, err)
result := uiDownloadResult{
Target: target.Name,
URL: target.DefaultURL,
ArtifactPath: artifactPath,
ArtifactType: strings.TrimPrefix(strings.ToLower(filepath.Ext(artifactPath)), "."),
SizeBytes: info.Size(),
}
if strings.EqualFold(filepath.Ext(artifactPath), ".zip") {
extractDir := filepath.Join(outputDir, target.OutputBaseName+"-"+time.Now().UTC().Format("20060102150405"))
exitIfError("failed creating extract dir", os.MkdirAll(extractDir, 0755))
exitIfError("failed extracting "+artifactPath, unzipUIArtifact(artifactPath, extractDir))
appPath, err := findUIInstallApp(extractDir)
exitIfError("failed finding .app in "+artifactPath, err)
result.AppPath = appPath
}
return result
}