Skip to content

Commit

Permalink
feat: support crashreport
Browse files Browse the repository at this point in the history
  • Loading branch information
electricbubble committed Apr 26, 2021
1 parent 41c2307 commit 6cfdad6
Showing 4 changed files with 67 additions and 3 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -56,6 +56,12 @@ $ gidevice xctest com.leixipaopao.WebDriverAgentRunner.xctrunner
$ gidevice syslog
```

#### CrashReport

```shell
$ gidevice crashreport /path/.../local/dir/ -e -k
```

## Thanks

| |About|
58 changes: 58 additions & 0 deletions cmd/crashreport.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package cmd

import (
"errors"
"fmt"
giDevice "github.com/electricbubble/gidevice"
"github.com/electricbubble/gidevice-cli/internal"
"path/filepath"

"github.com/spf13/cobra"
)

// crashreportCmd represents the crashreport command
var crashreportCmd = &cobra.Command{
Use: "crashreport",
Short: "Move crash reports from device to a local DIRECTORY.",
Run: func(cmd *cobra.Command, args []string) {
if len(args) == 0 {
internal.ErrorExit(errors.New("required parameter missing 'localDirectory'"))
}
localDirectory := args[0]
udid, _ := cmd.Flags().GetString("udid")
isKeep, _ := cmd.Flags().GetBool("keep")
isExtract, _ := cmd.Flags().GetBool("extract")

if !filepath.IsAbs(localDirectory) {
var err error
if localDirectory, err = filepath.Abs(localDirectory); err != nil {
internal.ErrorExit(err)
}
}

d, err := internal.GetDeviceFromCommand(udid)
internal.ErrorExit(err)

prefix := "Move"
if isKeep {
prefix = "Copy"
}
err = d.MoveCrashReport(localDirectory,
giDevice.WithKeepCrashReport(isKeep),
giDevice.WithExtractRawCrashReport(isExtract),
giDevice.WithWhenMoveIsDone(func(filename string) {
fmt.Printf("%s: %s\n", prefix, filename)
}),
)
internal.ErrorExit(err)
},
}

func init() {
rootCmd.AddCommand(crashreportCmd)

crashreportCmd.Flags().BoolP("keep", "k", false, "copy but do not remove crash reports from device")
crashreportCmd.Flags().BoolP("extract", "e", false, "extract raw crash report into separate '.crash' file")

crashreportCmd.Flags().StringP("udid", "u", "", "Device uuid")
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -3,7 +3,7 @@ module github.com/electricbubble/gidevice-cli
go 1.16

require (
github.com/electricbubble/gidevice v0.2.2
github.com/electricbubble/gidevice v0.3.0
github.com/mitchellh/go-homedir v1.1.0
github.com/spf13/cobra v1.1.3
github.com/spf13/viper v1.7.0
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
@@ -37,8 +37,8 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ=
github.com/dgryski/go-sip13 v0.0.0-20181026042036-e10d5fee7954/go.mod h1:vAd38F8PWV+bWy6jNmig1y/TA+kYO4g3RSRF0IAv0no=
github.com/electricbubble/gidevice v0.2.2 h1:uCYfARawc0kJTY22zBCKNAKYTcH/8LkLdLq/i3Okq6w=
github.com/electricbubble/gidevice v0.2.2/go.mod h1:hWRHIPf4uyiEB56hnVHVvu6MoVg7RlJY8ZV2FVgLKZA=
github.com/electricbubble/gidevice v0.3.0 h1:7BviJ3frVmV1iIBRl1max2oDczTQ6H7XwsqSHgGiwjI=
github.com/electricbubble/gidevice v0.3.0/go.mod h1:hWRHIPf4uyiEB56hnVHVvu6MoVg7RlJY8ZV2FVgLKZA=
github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4=
github.com/fsnotify/fsnotify v1.4.7 h1:IXs+QLmnXW2CcXuY+8Mzv/fWEsPGWxqefPtCP5CnV9I=
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=

0 comments on commit 6cfdad6

Please sign in to comment.