@@ -2,7 +2,6 @@ package php
22
33import (
44 "fmt"
5- "os"
65 "sort"
76 "strings"
87 "time"
@@ -14,7 +13,6 @@ import (
1413 "github.com/LumoSolutions/yerd/pkg/extensions"
1514 "github.com/LumoSolutions/yerd/pkg/php"
1615 "github.com/fatih/color"
17- "github.com/olekukonko/tablewriter"
1816 "github.com/spf13/cobra"
1917)
2018
@@ -110,7 +108,10 @@ func runAddExtensions(cmd *cobra.Command, args []string) error {
110108
111109 valid , invalid := extensions .ValidateExtensions (extensionsToAdd )
112110 if len (invalid ) > 0 {
113- color .New (color .FgRed ).Printf ("Invalid extensions: %s\n " , strings .Join (invalid , ", " ))
111+ utils .PrintError ("Invalid extensions:" )
112+ utils .PrintExtensionsGrid (invalid )
113+ fmt .Println ()
114+
114115 for _ , inv := range invalid {
115116 suggestions := extensions .SuggestSimilarExtensions (inv )
116117 if len (suggestions ) > 0 {
@@ -139,22 +140,28 @@ func runAddExtensions(cmd *cobra.Command, args []string) error {
139140 }
140141
141142 if len (alreadyInstalled ) > 0 {
142- color .New (color .FgYellow ).Printf ("Already installed: %s\n " , strings .Join (alreadyInstalled , ", " ))
143+ utils .PrintWarning ("Already installed:" )
144+ sort .Strings (alreadyInstalled )
145+ utils .PrintExtensionsGrid (alreadyInstalled )
146+ fmt .Println ()
143147 }
144148
145149 if len (newExtensions ) == 0 {
146- color . New ( color . FgYellow ). Printf ( "No new extensions to add for PHP %s\n " , phpVersion )
150+ utils . PrintWarning ( "No new extensions to add for PHP %s" , phpVersion )
147151 return nil
148152 }
149153
154+ utils .PrintInfo ("Adding extensions to PHP %s:" , phpVersion )
155+ sort .Strings (newExtensions )
156+ utils .PrintExtensionsGrid (newExtensions )
157+ fmt .Println ()
158+
150159 var finalExtensions []string
151160 for ext := range currentMap {
152161 finalExtensions = append (finalExtensions , ext )
153162 }
154163 sort .Strings (finalExtensions )
155164
156- color .New (color .FgGreen ).Printf ("Adding extensions to PHP %s: %s\n " , phpVersion , strings .Join (newExtensions , ", " ))
157-
158165 return applyExtensionChanges (cfg , phpVersion , finalExtensions )
159166}
160167
@@ -201,22 +208,28 @@ func runRemoveExtensions(cmd *cobra.Command, args []string) error {
201208 }
202209
203210 if len (notInstalled ) > 0 {
204- color .New (color .FgYellow ).Printf ("Not installed: %s\n " , strings .Join (notInstalled , ", " ))
211+ utils .PrintWarning ("Not installed:" )
212+ sort .Strings (notInstalled )
213+ utils .PrintExtensionsGrid (notInstalled )
214+ fmt .Println ()
205215 }
206216
207217 if len (removedExtensions ) == 0 {
208- color . New ( color . FgYellow ). Printf ( "No extensions to remove from PHP %s\n " , phpVersion )
218+ utils . PrintWarning ( "No extensions to remove from PHP %s" , phpVersion )
209219 return nil
210220 }
211221
222+ utils .PrintInfo ("Removing extensions from PHP %s:" , phpVersion )
223+ sort .Strings (removedExtensions )
224+ utils .PrintExtensionsGrid (removedExtensions )
225+ fmt .Println ()
226+
212227 var finalExtensions []string
213228 for ext := range currentMap {
214229 finalExtensions = append (finalExtensions , ext )
215230 }
216231 sort .Strings (finalExtensions )
217232
218- color .New (color .FgRed ).Printf ("Removing extensions from PHP %s: %s\n " , phpVersion , strings .Join (removedExtensions , ", " ))
219-
220233 return applyExtensionChanges (cfg , phpVersion , finalExtensions )
221234}
222235
@@ -246,7 +259,10 @@ func runReplaceExtensions(cmd *cobra.Command, args []string) error {
246259
247260 valid , invalid := extensions .ValidateExtensions (newExtensions )
248261 if len (invalid ) > 0 {
249- color .New (color .FgRed ).Printf ("Invalid extensions: %s\n " , strings .Join (invalid , ", " ))
262+ utils .PrintError ("Invalid extensions:" )
263+ utils .PrintExtensionsGrid (invalid )
264+ fmt .Println ()
265+
250266 for _ , inv := range invalid {
251267 suggestions := extensions .SuggestSimilarExtensions (inv )
252268 if len (suggestions ) > 0 {
@@ -261,66 +277,40 @@ func runReplaceExtensions(cmd *cobra.Command, args []string) error {
261277 sort .Strings (currentExtensions )
262278
263279 if fmt .Sprintf ("%v" , valid ) == fmt .Sprintf ("%v" , currentExtensions ) {
264- color .New (color .FgYellow ).Printf ("Extensions for PHP %s are already set to: %s\n " , phpVersion , strings .Join (valid , ", " ))
280+ utils .PrintWarning ("Extensions for PHP %s are already set to:" , phpVersion )
281+ utils .PrintExtensionsGrid (valid )
265282 return nil
266283 }
267284
268- color .New (color .FgCyan ).Printf ("Replacing all extensions for PHP %s with: %s\n " , phpVersion , strings .Join (valid , ", " ))
285+ utils .PrintInfo ("Replacing all extensions for PHP %s with:" , phpVersion )
286+ utils .PrintExtensionsGrid (valid )
287+ fmt .Println ()
269288
270289 return applyExtensionChanges (cfg , phpVersion , valid )
271290}
272291
273- // listExtensions displays formatted tables of installed and available extensions for a PHP version.
292+ // listExtensions displays installed and available extensions in grid format for a PHP version.
274293// cfg: Configuration object, version: PHP version string. Returns error if version data not found.
275294func listExtensions (cfg * config.Config , version string ) error {
276295 installedExtensions , exists := cfg .GetPHPExtensions (version )
277296 if ! exists {
278297 return fmt .Errorf ("no extension information found for PHP %s" , version )
279298 }
280299
281- color .New (color .FgCyan , color .Bold ).Printf ("PHP %s Extensions\n \n " , version )
300+ utils .PrintInfo ("PHP %s Extensions:" , version )
301+ fmt .Println ()
282302
283- color . New ( color . FgGreen , color . Bold ). Println ( "✓ INSTALLED:" )
303+ utils . PrintSuccess ( " INSTALLED:" )
284304 if len (installedExtensions ) == 0 {
285- color . New ( color . FgYellow ) .Println (" No extensions installed" )
305+ fmt .Println (" No extensions installed" )
286306 } else {
287- installedTable := tablewriter .NewWriter (os .Stdout )
288- installedTable .SetHeader ([]string {"Extension" , "Category" , "Description" })
289- installedTable .SetBorder (false )
290- installedTable .SetHeaderAlignment (tablewriter .ALIGN_LEFT )
291- installedTable .SetAlignment (tablewriter .ALIGN_LEFT )
292- installedTable .SetCenterSeparator ("" )
293- installedTable .SetColumnSeparator ("" )
294- installedTable .SetRowSeparator ("" )
295- installedTable .SetHeaderLine (false )
296- installedTable .SetTablePadding (" " )
297- installedTable .SetNoWhiteSpace (true )
298-
299307 sort .Strings (installedExtensions )
300-
301- for _ , extName := range installedExtensions {
302- if ext , exists := extensions .AvailableExtensions [extName ]; exists {
303- installedTable .Append ([]string {
304- color .New (color .FgGreen ).Sprint (extName ),
305- color .New (color .FgBlue ).Sprint (ext .Category ),
306- ext .Description ,
307- })
308- } else {
309- installedTable .Append ([]string {
310- color .New (color .FgRed ).Sprint (extName ),
311- color .New (color .FgYellow ).Sprint ("unknown" ),
312- "Unknown extension" ,
313- })
314- }
315- }
316-
317- installedTable .Render ()
308+ utils .PrintExtensionsGrid (installedExtensions )
318309 }
319310
320311 fmt .Println ()
321312
322- color .New (color .FgBlue , color .Bold ).Println ("⊡ AVAILABLE:" )
323-
313+ utils .PrintInfo ("AVAILABLE:" )
324314 installedMap := make (map [string ]bool )
325315 for _ , ext := range installedExtensions {
326316 installedMap [ext ] = true
@@ -334,44 +324,18 @@ func listExtensions(cfg *config.Config, version string) error {
334324 }
335325
336326 if len (availableExtensions ) == 0 {
337- color . New ( color . FgYellow ) .Println (" All available extensions are already installed" )
327+ fmt .Println (" All available extensions are already installed" )
338328 } else {
339- availableTable := tablewriter .NewWriter (os .Stdout )
340- availableTable .SetHeader ([]string {"Extension" , "Category" , "Description" })
341- availableTable .SetBorder (false )
342- availableTable .SetHeaderAlignment (tablewriter .ALIGN_LEFT )
343- availableTable .SetAlignment (tablewriter .ALIGN_LEFT )
344- availableTable .SetCenterSeparator ("" )
345- availableTable .SetColumnSeparator ("" )
346- availableTable .SetRowSeparator ("" )
347- availableTable .SetHeaderLine (false )
348- availableTable .SetTablePadding (" " )
349- availableTable .SetNoWhiteSpace (true )
350-
351329 sort .Strings (availableExtensions )
352-
353- for _ , extName := range availableExtensions {
354- ext := extensions .AvailableExtensions [extName ]
355- availableTable .Append ([]string {
356- color .New (color .FgWhite ).Sprint (extName ),
357- color .New (color .FgCyan ).Sprint (ext .Category ),
358- ext .Description ,
359- })
360- }
361-
362- availableTable .Render ()
330+ utils .PrintExtensionsGrid (availableExtensions )
363331 }
364332
365333 fmt .Println ()
366- color .New (color .FgMagenta , color .Bold ).Println ("USAGE:" )
367- fmt .Printf (" %s add %s <extension> # Add extensions\n " ,
368- color .New (color .FgWhite ).Sprint ("yerd php extensions" ), version )
369- fmt .Printf (" %s remove %s <extension> # Remove extensions\n " ,
370- color .New (color .FgWhite ).Sprint ("yerd php extensions" ), version )
371- fmt .Printf (" %s replace %s <extension> # Replace all extensions\n " ,
372- color .New (color .FgWhite ).Sprint ("yerd php extensions" ), version )
373- fmt .Printf (" %s %s # Force rebuild with current extensions\n " ,
374- color .New (color .FgWhite ).Sprint ("yerd php rebuild" ), version )
334+ utils .PrintInfo ("USAGE:" )
335+ fmt .Printf (" yerd php extensions add %s <extension> # Add extensions\n " , version )
336+ fmt .Printf (" yerd php extensions remove %s <extension> # Remove extensions\n " , version )
337+ fmt .Printf (" yerd php extensions replace %s <extension> # Replace all extensions\n " , version )
338+ fmt .Printf (" yerd php rebuild %s # Force rebuild with current extensions\n " , version )
375339
376340 return nil
377341}
@@ -405,7 +369,7 @@ func applyExtensionChanges(cfg *config.Config, version string, extensions []stri
405369
406370 err := rebuildPHPWithExtensions (version , extensions )
407371 done <- true
408- fmt .Print ("\r " )
372+ fmt .Print ("\r \033 [K" ) // Clear the entire line
409373
410374 if err != nil {
411375 color .New (color .FgRed ).Printf ("✗ Failed to rebuild PHP %s: %v\n " , version , err )
@@ -426,7 +390,7 @@ func applyExtensionChanges(cfg *config.Config, version string, extensions []stri
426390 color .New (color .FgRed ).Printf ("⚠️ Warning: Build succeeded but failed to save configuration: %v\n " , err )
427391 }
428392
429- color .New (color .FgGreen ).Printf ("✓ Successfully updated PHP %s extensions: %s \n " , version , strings . Join ( extensions , ", " ) )
393+ color .New (color .FgGreen ).Printf ("✓ Successfully updated PHP %s extensions\n " , version )
430394 return nil
431395}
432396
0 commit comments