42 lines
919 B
Go
42 lines
919 B
Go
package cmd
|
|
|
|
import (
|
|
"io"
|
|
|
|
"github.com/olekukonko/tablewriter"
|
|
"github.com/spf13/cobra"
|
|
)
|
|
|
|
func ModulesListCommand(
|
|
initializer LevelInitializer,
|
|
registryAcc TypeRegistryAccessor,
|
|
out io.Writer,
|
|
) *cobra.Command {
|
|
return &cobra.Command{
|
|
Use: "list",
|
|
Aliases: []string{"ls", "dir"},
|
|
Short: "List all known modules",
|
|
SilenceUsage: true,
|
|
SilenceErrors: true,
|
|
Args: cobra.NoArgs,
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
|
if err := initializer.InitAt(cmd.Context(), InitLevelBuildRConfig); err != nil {
|
|
return err
|
|
}
|
|
|
|
table := tablewriter.NewWriter(out)
|
|
table.SetHeader([]string{"Category", "Module"})
|
|
table.SetBorder(false)
|
|
|
|
for category, modules := range registryAcc.TypeRegistry().Inventory() {
|
|
for _, m := range modules {
|
|
table.Append([]string{category.String(), m})
|
|
}
|
|
}
|
|
|
|
table.Render()
|
|
return nil
|
|
},
|
|
}
|
|
}
|