From aadc3cd96449129cddb2d99248e1f11e3b54d2fd Mon Sep 17 00:00:00 2001 From: blacktop Date: Wed, 7 Aug 2024 15:09:22 -0600 Subject: [PATCH] chore: add `--json` to `ipsw ota info` cmd --- cmd/ipsw/cmd/ota/ota_info.go | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/cmd/ipsw/cmd/ota/ota_info.go b/cmd/ipsw/cmd/ota/ota_info.go index 4a9c05f84..0e502ca36 100644 --- a/cmd/ipsw/cmd/ota/ota_info.go +++ b/cmd/ipsw/cmd/ota/ota_info.go @@ -22,6 +22,7 @@ THE SOFTWARE. package ota import ( + "encoding/json" "fmt" "github.com/apex/log" @@ -33,6 +34,8 @@ import ( func init() { OtaCmd.AddCommand(otaInfoCmd) + otaInfoCmd.Flags().BoolP("json", "j", false, "Output as JSON") + viper.BindPFlag("ota.info.json", otaInfoCmd.Flags().Lookup("json")) } // otaInfoCmd represents the info command @@ -59,9 +62,17 @@ var otaInfoCmd = &cobra.Command{ return fmt.Errorf("failed to get OTA info: %v", err) } - fmt.Println("\n[OTA Info]") - fmt.Println("==========") - fmt.Println(inf) + if viper.GetBool("ota.info.json") { + dat, err := json.Marshal(inf) + if err != nil { + return fmt.Errorf("failed to marshal OTA info: %v", err) + } + fmt.Println(string(dat)) + } else { + fmt.Println("\n[OTA Info]") + fmt.Println("==========") + fmt.Println(inf) + } return nil