@@ -178,15 +178,15 @@ func newPlansAvailabilityCmd() *cobra.Command {
178178// --- Grouped Plans (for plans list command) ---
179179
180180type groupedPlan struct {
181- Slug string
182- CPU string
183- Drives string
184- NIC string
185- ID string
186- AvailableIn []string
187- InStock []string
188- Features []string
189- Memory string
181+ Slug string `json:"slug"`
182+ CPU string `json:"cpu"`
183+ Drives string `json:"drives"`
184+ NIC string `json:"nic"`
185+ ID string `json:"id"`
186+ AvailableIn []string `json:"available_in"`
187+ InStock []string `json:"in_stock"`
188+ Features []string `json:"features"`
189+ Memory string `json:"memory"`
190190}
191191
192192func groupPlans (pr * plansResponse , gpu bool , name , slug string , inStock bool , location , stockLevel string , diskEql , diskGte , diskLte , ramEql , ramGte , ramLte int ) []groupedPlan {
@@ -350,6 +350,12 @@ func renderGroupedPlans(plans []groupedPlan) {
350350 return
351351 }
352352
353+ // Check if JSON output was requested
354+ if viper .GetBool ("json" ) || viper .GetString ("output" ) == "json" {
355+ renderGroupedPlansJSON (plans )
356+ return
357+ }
358+
353359 if os .Getenv ("LSH_CLASSIC_OUTPUT" ) == "true" {
354360 renderGroupedPlansClassic (plans )
355361 return
@@ -451,6 +457,15 @@ func wrapLocationsSmartLimit(locs []string, maxDisplay int) string {
451457 return fmt .Sprintf ("%s, +%d" , displayed , remaining )
452458}
453459
460+ func renderGroupedPlansJSON (plans []groupedPlan ) {
461+ jsonData , err := json .MarshalIndent (plans , "" , " " )
462+ if err != nil {
463+ fmt .Println ("Could not encode plans as JSON." )
464+ return
465+ }
466+ fmt .Println (string (jsonData ))
467+ }
468+
454469func renderGroupedPlansClassic (plans []groupedPlan ) {
455470 table := tablewriter .NewWriter (os .Stdout )
456471 table .SetHeader ([]string {"SLUG" , "CPU" , "DRIVES" , "NIC" , "ID" , "FEATURES" , "MEMORY" , "AVAILABLE IN" , "IN STOCK" })
0 commit comments