From 6cfdad67bdee98ac10b50d4be60c6093443e8152 Mon Sep 17 00:00:00 2001 From: electricbubble Date: Tue, 27 Apr 2021 00:36:43 +0800 Subject: [PATCH] feat: support `crashreport` --- README.md | 6 +++++ cmd/crashreport.go | 58 ++++++++++++++++++++++++++++++++++++++++++++++ go.mod | 2 +- go.sum | 4 ++-- 4 files changed, 67 insertions(+), 3 deletions(-) create mode 100644 cmd/crashreport.go diff --git a/README.md b/README.md index 09db28b..d0651e1 100644 --- a/README.md +++ b/README.md @@ -56,6 +56,12 @@ $ gidevice xctest com.leixipaopao.WebDriverAgentRunner.xctrunner $ gidevice syslog ``` +#### CrashReport + +```shell +$ gidevice crashreport /path/.../local/dir/ -e -k +``` + ## Thanks | |About| diff --git a/cmd/crashreport.go b/cmd/crashreport.go new file mode 100644 index 0000000..a9d6f5f --- /dev/null +++ b/cmd/crashreport.go @@ -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") +} diff --git a/go.mod b/go.mod index 3747277..a187eb5 100644 --- a/go.mod +++ b/go.mod @@ -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 diff --git a/go.sum b/go.sum index 089fc47..365a8ab 100644 --- a/go.sum +++ b/go.sum @@ -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=