diff --git a/README.md b/README.md index c4051d9..6d89897 100644 --- a/README.md +++ b/README.md @@ -259,10 +259,10 @@ Example output for `agent status`: ```bash # List crash reports from a device -mobilecli crashes list --device +mobilecli device crashes list --device # Get a specific crash report by ID -mobilecli crashes get --device +mobilecli device crashes get --device ``` Example output for `crashes list`: diff --git a/cli/crashes.go b/cli/crashes.go index e9efb8d..ba57f2f 100644 --- a/cli/crashes.go +++ b/cli/crashes.go @@ -8,8 +8,9 @@ import ( ) var crashesCmd = &cobra.Command{ - Use: "crashes", - Short: "Manage crash reports from devices", + Use: "crashes", + Short: "Manage crash reports from devices", + Deprecated: "use 'device crashes' instead", } var crashesListCmd = &cobra.Command{ diff --git a/cli/device_crashes.go b/cli/device_crashes.go new file mode 100644 index 0000000..50e3f62 --- /dev/null +++ b/cli/device_crashes.go @@ -0,0 +1,50 @@ +package cli + +import ( + "fmt" + + "github.com/mobile-next/mobilecli/commands" + "github.com/spf13/cobra" +) + +var deviceCrashesCmd = &cobra.Command{ + Use: "crashes", + Short: "Manage crash reports from a device", +} + +var deviceCrashesListCmd = &cobra.Command{ + Use: "list", + Short: "List crash reports from a device", + RunE: func(cmd *cobra.Command, args []string) error { + response := commands.CrashesListCommand(deviceId) + printJson(response) + if response.Status == "error" { + return fmt.Errorf("%s", response.Error) + } + return nil + }, +} + +var deviceCrashesGetCmd = &cobra.Command{ + Use: "get [id]", + Short: "Get a crash report by ID", + Args: cobra.ExactArgs(1), + RunE: func(cmd *cobra.Command, args []string) error { + response := commands.CrashesGetCommand(deviceId, args[0]) + printJson(response) + if response.Status == "error" { + return fmt.Errorf("%s", response.Error) + } + return nil + }, +} + +func init() { + deviceCmd.AddCommand(deviceCrashesCmd) + + deviceCrashesCmd.AddCommand(deviceCrashesListCmd) + deviceCrashesCmd.AddCommand(deviceCrashesGetCmd) + + deviceCrashesListCmd.Flags().StringVar(&deviceId, "device", "", "ID of the device to list crashes from") + deviceCrashesGetCmd.Flags().StringVar(&deviceId, "device", "", "ID of the device to get crash from") +} diff --git a/cli/root.go b/cli/root.go index 651e88d..63d787d 100644 --- a/cli/root.go +++ b/cli/root.go @@ -93,10 +93,10 @@ INPUT/OUTPUT: CRASH REPORTS: # List crash reports from a device - mobilecli crashes list --device + mobilecli device crashes list --device # Get a specific crash report - mobilecli crashes get --device + mobilecli device crashes get --device AGENT: # Check agent installation status