|
| 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 | +} |
0 commit comments