Skip to content

Commit 6cfdad6

Browse files
feat: support crashreport
1 parent 41c2307 commit 6cfdad6

File tree

4 files changed

+67
-3
lines changed

4 files changed

+67
-3
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,12 @@ $ gidevice xctest com.leixipaopao.WebDriverAgentRunner.xctrunner
5656
$ gidevice syslog
5757
```
5858

59+
#### CrashReport
60+
61+
```shell
62+
$ gidevice crashreport /path/.../local/dir/ -e -k
63+
```
64+
5965
## Thanks
6066

6167
| |About|

cmd/crashreport.go

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
package cmd
2+
3+
import (
4+
"errors"
5+
"fmt"
6+
giDevice "github.com/electricbubble/gidevice"
7+
"github.com/electricbubble/gidevice-cli/internal"
8+
"path/filepath"
9+
10+
"github.com/spf13/cobra"
11+
)
12+
13+
// crashreportCmd represents the crashreport command
14+
var crashreportCmd = &cobra.Command{
15+
Use: "crashreport",
16+
Short: "Move crash reports from device to a local DIRECTORY.",
17+
Run: func(cmd *cobra.Command, args []string) {
18+
if len(args) == 0 {
19+
internal.ErrorExit(errors.New("required parameter missing 'localDirectory'"))
20+
}
21+
localDirectory := args[0]
22+
udid, _ := cmd.Flags().GetString("udid")
23+
isKeep, _ := cmd.Flags().GetBool("keep")
24+
isExtract, _ := cmd.Flags().GetBool("extract")
25+
26+
if !filepath.IsAbs(localDirectory) {
27+
var err error
28+
if localDirectory, err = filepath.Abs(localDirectory); err != nil {
29+
internal.ErrorExit(err)
30+
}
31+
}
32+
33+
d, err := internal.GetDeviceFromCommand(udid)
34+
internal.ErrorExit(err)
35+
36+
prefix := "Move"
37+
if isKeep {
38+
prefix = "Copy"
39+
}
40+
err = d.MoveCrashReport(localDirectory,
41+
giDevice.WithKeepCrashReport(isKeep),
42+
giDevice.WithExtractRawCrashReport(isExtract),
43+
giDevice.WithWhenMoveIsDone(func(filename string) {
44+
fmt.Printf("%s: %s\n", prefix, filename)
45+
}),
46+
)
47+
internal.ErrorExit(err)
48+
},
49+
}
50+
51+
func init() {
52+
rootCmd.AddCommand(crashreportCmd)
53+
54+
crashreportCmd.Flags().BoolP("keep", "k", false, "copy but do not remove crash reports from device")
55+
crashreportCmd.Flags().BoolP("extract", "e", false, "extract raw crash report into separate '.crash' file")
56+
57+
crashreportCmd.Flags().StringP("udid", "u", "", "Device uuid")
58+
}

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ module github.com/electricbubble/gidevice-cli
33
go 1.16
44

55
require (
6-
github.com/electricbubble/gidevice v0.2.2
6+
github.com/electricbubble/gidevice v0.3.0
77
github.com/mitchellh/go-homedir v1.1.0
88
github.com/spf13/cobra v1.1.3
99
github.com/spf13/viper v1.7.0

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c
3737
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
3838
github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ=
3939
github.com/dgryski/go-sip13 v0.0.0-20181026042036-e10d5fee7954/go.mod h1:vAd38F8PWV+bWy6jNmig1y/TA+kYO4g3RSRF0IAv0no=
40-
github.com/electricbubble/gidevice v0.2.2 h1:uCYfARawc0kJTY22zBCKNAKYTcH/8LkLdLq/i3Okq6w=
41-
github.com/electricbubble/gidevice v0.2.2/go.mod h1:hWRHIPf4uyiEB56hnVHVvu6MoVg7RlJY8ZV2FVgLKZA=
40+
github.com/electricbubble/gidevice v0.3.0 h1:7BviJ3frVmV1iIBRl1max2oDczTQ6H7XwsqSHgGiwjI=
41+
github.com/electricbubble/gidevice v0.3.0/go.mod h1:hWRHIPf4uyiEB56hnVHVvu6MoVg7RlJY8ZV2FVgLKZA=
4242
github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4=
4343
github.com/fsnotify/fsnotify v1.4.7 h1:IXs+QLmnXW2CcXuY+8Mzv/fWEsPGWxqefPtCP5CnV9I=
4444
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=

0 commit comments

Comments
 (0)