2020 resourcesList = make (map [string ][]string )
2121)
2222
23- func Parser (output []byte , showTags , showUnchanged , compact , useMarkdown bool , useJson bool , metrics bool ) {
23+ func Parser (output []byte , showTags , showUnchanged , compact , useMarkdown bool , useJson bool , metrics bool , prettyJSON bool ) {
2424 var data tfjson.Plan
2525 if err := json .Unmarshal (output , & data ); err != nil {
2626 fmt .Printf ("Error unmarshalling plan: %v\n " , err )
@@ -31,7 +31,7 @@ func Parser(output []byte, showTags, showUnchanged, compact, useMarkdown bool, u
3131 processResourceChange (resourceChange , showTags )
3232 }
3333
34- PrintPlanSummary (showTags , showUnchanged , compact , useMarkdown , useJson , metrics )
34+ PrintPlanSummary (showTags , showUnchanged , compact , useMarkdown , useJson , metrics , prettyJSON )
3535}
3636
3737func processResourceChange (resourceChange * tfjson.ResourceChange , showTags bool ) {
@@ -140,7 +140,7 @@ func PrintResources(message string, resources []string, bulletSymbol string, col
140140 }
141141}
142142
143- func PrintPlanSummary (showTags , showUnchanged , compact , useMarkdown bool , useJson bool , metrics bool ) {
143+ func PrintPlanSummary (showTags , showUnchanged , compact , useMarkdown bool , useJson bool , metrics bool , prettyJSON bool ) {
144144 if ! useJson {
145145 if showUnchanged {
146146 PrintResources ("🔵 Unchanged:" , resourcesList [NOOP ], "•" , color .New (color .FgBlue ), compact , useMarkdown )
@@ -152,11 +152,11 @@ func PrintPlanSummary(showTags, showUnchanged, compact, useMarkdown bool, useJso
152152 PrintResources ("🟡 Update:" , resourcesList [UPDATE ], "~" , color .New (color .FgYellow ), compact , useMarkdown )
153153 PrintResources ("🔴 Destroy:" , resourcesList [DELETE ], "-" , color .New (color .FgRed ), compact , useMarkdown )
154154 } else {
155- PrintResourcesJson (showTags , showUnchanged , metrics )
155+ PrintResourcesJson (showTags , showUnchanged , metrics , prettyJSON )
156156 }
157157}
158158
159- func PrintResourcesJson (showTags bool , showUnchanged bool , metrics bool ) {
159+ func PrintResourcesJson (showTags bool , showUnchanged bool , metrics bool , prettyJSON bool ) {
160160 if metrics {
161161 var metricsData = make (map [string ]int )
162162
@@ -172,8 +172,14 @@ func PrintResourcesJson(showTags bool, showUnchanged bool, metrics bool) {
172172 metricsData ["update" ] = len (resourcesList [UPDATE ])
173173 metricsData ["delete" ] = len (resourcesList [DELETE ])
174174
175- result , _ := json .Marshal (metricsData )
176- fmt .Println (string (result ))
175+ if prettyJSON {
176+ result , _ := json .MarshalIndent (metricsData , "" , " " )
177+ fmt .Println (string (result ))
178+ } else {
179+ result , _ := json .Marshal (metricsData )
180+ fmt .Println (string (result ))
181+ }
182+
177183 } else {
178184 var data = make (map [string ][]string )
179185
@@ -197,8 +203,13 @@ func PrintResourcesJson(showTags bool, showUnchanged bool, metrics bool) {
197203 data ["delete" ] = resourcesList [DELETE ]
198204 }
199205
200- result , _ := json .Marshal (data )
201- fmt .Println (string (result ))
206+ if prettyJSON {
207+ result , _ := json .MarshalIndent (data , "" , " " ) //json.Marshal(data)
208+ fmt .Println (string (result ))
209+ } else {
210+ result , _ := json .Marshal (data )
211+ fmt .Println (string (result ))
212+ }
202213 }
203214}
204215
0 commit comments