MCPcopy Create free account
hub / github.com/chainloop-dev/chainloop / pluginInfoFlagsTableOutput

Function pluginInfoFlagsTableOutput

app/cli/cmd/plugins.go:398–449  ·  view source on GitHub ↗
(plugin *plugins.LoadedPlugin)

Source from the content-addressed store, hash-verified

396}
397
398func pluginInfoFlagsTableOutput(plugin *plugins.LoadedPlugin) {
399 if len(plugin.Metadata.Commands) == 0 {
400 return
401 }
402
403 flagsPresent := false
404 for _, cmd := range plugin.Metadata.Commands {
405 if len(cmd.Flags) > 0 {
406 flagsPresent = true
407 }
408 }
409
410 if !flagsPresent {
411 return
412 }
413
414 for _, cmd := range plugin.Metadata.Commands {
415 t := output.NewTableWriter()
416 t.SetTitle(fmt.Sprintf("Command: %s", cmd.Name))
417 t.AppendSeparator()
418
419 flagDetails := "Flags:\n"
420
421 // Find the longest flag name to align descriptions properly
422 maxFlagLen := 0
423 for _, flag := range cmd.Flags {
424 if len(flag.Name) > maxFlagLen {
425 maxFlagLen = len(flag.Name)
426 }
427 }
428
429 maxFlagLen += 2 // For the "--" prefix
430 for _, flag := range cmd.Flags {
431 shorthand := " "
432 if flag.Shorthand != "" {
433 shorthand = fmt.Sprintf("-%s,", flag.Shorthand)
434 }
435 flagName := fmt.Sprintf(" %s--%s", shorthand, flag.Name)
436 padding := strings.Repeat(" ", maxFlagLen-len(flag.Name)+2)
437
438 defaultValue := ""
439 if flag.Default != nil {
440 defaultValue = fmt.Sprintf(" (default: %v)", flag.Default)
441 }
442
443 flagDetails += fmt.Sprintf("%s%s%s%s\n", flagName, padding, flag.Description, defaultValue)
444 }
445
446 t.AppendRow(table.Row{flagDetails})
447 t.Render()
448 }
449}

Callers 1

pluginInfoTableOutputFunction · 0.85

Calls 2

NewTableWriterFunction · 0.92
RenderMethod · 0.80

Tested by

no test coverage detected