From 66d1e2afefb91f864d6e611f826a1370cf638306 Mon Sep 17 00:00:00 2001 From: gmegidish Date: Thu, 30 Apr 2026 21:38:42 +0200 Subject: [PATCH] refactor: move crashes commands under device crashes, deprecate root crashes - add device crashes list and device crashes get subcommands - mark root crashes command as deprecated (warns via stderr, hidden from help) - update root.go examples and README to use new device crashes path --- README.md | 4 ++-- cli/crashes.go | 5 +++-- cli/device_crashes.go | 50 +++++++++++++++++++++++++++++++++++++++++++ cli/root.go | 4 ++-- 4 files changed, 57 insertions(+), 6 deletions(-) create mode 100644 cli/device_crashes.go 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