@@ -20,6 +20,7 @@ import (
2020 "fmt"
2121 "os"
2222 "strconv"
23+ "strings"
2324
2425 "github.com/chainloop-dev/chainloop/app/cli/internal/action"
2526 "github.com/chainloop-dev/chainloop/app/cli/pkg/plugins"
@@ -340,28 +341,19 @@ func pluginListTableOutput(plugins map[string]*plugins.LoadedPlugin) {
340341
341342func pluginInfoTableOutput (plugin * plugins.LoadedPlugin ) {
342343 t := newTableWriter ()
343-
344- t .AppendHeader (table.Row {"Name" , "Version" , "Description" , "Commands" })
345- t .AppendRow (table.Row {plugin .Metadata .Name , plugin .Metadata .Version , plugin .Metadata .Description , fmt .Sprintf ("%d command(s)" , len (plugin .Metadata .Commands ))})
346-
344+ t .SetTitle (fmt .Sprintf ("Plugin: %s" , plugin .Metadata .Name ))
345+ t .AppendSeparator ()
346+ t .AppendRow (table.Row {"Version" , plugin .Metadata .Version })
347+ t .AppendSeparator ()
348+ t .AppendRow (table.Row {"Description" , plugin .Metadata .Description })
349+ t .AppendSeparator ()
350+ t .AppendRow (table.Row {"Commands" , fmt .Sprintf ("%d command(s)" , len (plugin .Metadata .Commands ))})
351+ t .AppendSeparator ()
347352 t .Render ()
348353
349- pluginInfoCommandsTableOutput (plugin )
350354 pluginInfoFlagsTableOutput (plugin )
351355}
352356
353- func pluginInfoCommandsTableOutput (plugin * plugins.LoadedPlugin ) {
354- t := newTableWriter ()
355-
356- t .AppendHeader (table.Row {"Plugin" , "Command" , "Description" , "Usage" })
357- for _ , cmd := range plugin .Metadata .Commands {
358- t .AppendRow (table.Row {plugin .Metadata .Name , cmd .Name , cmd .Description , cmd .Usage })
359- t .AppendSeparator ()
360- }
361-
362- t .Render ()
363- }
364-
365357func pluginInfoFlagsTableOutput (plugin * plugins.LoadedPlugin ) {
366358 if len (plugin .Metadata .Commands ) == 0 {
367359 return
@@ -378,15 +370,39 @@ func pluginInfoFlagsTableOutput(plugin *plugins.LoadedPlugin) {
378370 return
379371 }
380372
381- t := newTableWriter ()
382-
383- t .AppendHeader (table.Row {"Plugin" , "Command" , "Flag" , "Description" , "Type" , "Default" , "Required" })
384373 for _ , cmd := range plugin .Metadata .Commands {
374+ t := newTableWriter ()
375+ t .SetTitle (fmt .Sprintf ("Command: %s" , cmd .Name ))
376+ t .AppendSeparator ()
377+
378+ flagDetails := "Flags:\n "
379+
380+ // Find the longest flag name to align descriptions properly
381+ maxFlagLen := 0
385382 for _ , flag := range cmd .Flags {
386- t .AppendRow (table.Row {plugin .Metadata .Name , cmd .Name , flag .Name , flag .Description , flag .Type , flag .Default , flag .Required })
387- t .AppendSeparator ()
383+ if len (flag .Name ) > maxFlagLen {
384+ maxFlagLen = len (flag .Name )
385+ }
388386 }
389- }
390387
391- t .Render ()
388+ maxFlagLen += 2 // For the "--" prefix
389+ for _ , flag := range cmd .Flags {
390+ shorthand := " "
391+ if flag .Shorthand != "" {
392+ shorthand = fmt .Sprintf ("-%s," , flag .Shorthand )
393+ }
394+ flagName := fmt .Sprintf (" %s--%s" , shorthand , flag .Name )
395+ padding := strings .Repeat (" " , maxFlagLen - len (flag .Name )+ 2 )
396+
397+ defaultValue := ""
398+ if flag .Default != nil {
399+ defaultValue = fmt .Sprintf (" (default: %v)" , flag .Default )
400+ }
401+
402+ flagDetails += fmt .Sprintf ("%s%s%s%s\n " , flagName , padding , flag .Description , defaultValue )
403+ }
404+
405+ t .AppendRow (table.Row {flagDetails })
406+ t .Render ()
407+ }
392408}
0 commit comments