forked from toolshed/abra
refactor: break up recipe cli package
This commit is contained in:
34
cli/recipe/list.go
Normal file
34
cli/recipe/list.go
Normal file
@ -0,0 +1,34 @@
|
||||
package recipe
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"sort"
|
||||
|
||||
"coopcloud.tech/abra/cli/formatter"
|
||||
"coopcloud.tech/abra/pkg/catalogue"
|
||||
"github.com/sirupsen/logrus"
|
||||
"github.com/urfave/cli/v2"
|
||||
)
|
||||
|
||||
var recipeListCommand = &cli.Command{
|
||||
Name: "list",
|
||||
Usage: "List available recipes",
|
||||
Aliases: []string{"ls"},
|
||||
Action: func(c *cli.Context) error {
|
||||
catl, err := catalogue.ReadRecipeCatalogue()
|
||||
if err != nil {
|
||||
logrus.Fatal(err.Error())
|
||||
}
|
||||
recipes := catl.Flatten()
|
||||
sort.Sort(catalogue.ByRecipeName(recipes))
|
||||
tableCol := []string{"Name", "Category", "Status"}
|
||||
table := formatter.CreateTable(tableCol)
|
||||
for _, recipe := range recipes {
|
||||
status := fmt.Sprintf("%v", recipe.Features.Status)
|
||||
tableRow := []string{recipe.Name, recipe.Category, status}
|
||||
table.Append(tableRow)
|
||||
}
|
||||
table.Render()
|
||||
return nil
|
||||
},
|
||||
}
|
Reference in New Issue
Block a user