feat: filter recipes list
continuous-integration/drone/push Build is passing Details

This commit is contained in:
decentral1se 2021-12-27 11:00:04 +01:00
parent 37e48f262b
commit 3eef1e8587
Signed by: decentral1se
GPG Key ID: 03789458B3D0C410
1 changed files with 27 additions and 3 deletions

View File

@ -4,6 +4,7 @@ import (
"fmt"
"sort"
"strconv"
"strings"
"coopcloud.tech/abra/cli/formatter"
"coopcloud.tech/abra/pkg/catalogue"
@ -11,10 +12,22 @@ import (
"github.com/urfave/cli/v2"
)
var pattern string
var patternFlag = &cli.StringFlag{
Name: "pattern",
Value: "",
Aliases: []string{"p"},
Usage: "Simple string to filter recipes",
Destination: &pattern,
}
var recipeListCommand = &cli.Command{
Name: "list",
Usage: "List available recipes",
Aliases: []string{"ls"},
Flags: []cli.Flag{
patternFlag,
},
Action: func(c *cli.Context) error {
catl, err := catalogue.ReadRecipeCatalogue()
if err != nil {
@ -24,7 +37,7 @@ var recipeListCommand = &cli.Command{
recipes := catl.Flatten()
sort.Sort(catalogue.ByRecipeName(recipes))
tableCol := []string{"name", "category", "status", "healthcheck", "backups", "email", "SSO"}
tableCol := []string{"name", "category", "status", "healthcheck", "backups", "email", "tests", "SSO"}
table := formatter.CreateTable(tableCol)
for _, recipe := range recipes {
@ -35,13 +48,24 @@ var recipeListCommand = &cli.Command{
recipe.Features.Healthcheck,
recipe.Features.Backups,
recipe.Features.Email,
recipe.Features.Tests,
recipe.Features.SSO,
}
table.Append(tableRow)
if pattern != "" {
if strings.Contains(recipe.Name, pattern) {
table.Append(tableRow)
}
} else {
table.Append(tableRow)
}
}
table.SetCaption(true, fmt.Sprintf("total recipes: %v", len(recipes)))
table.Render()
if table.NumLines() > 0 {
table.Render()
}
return nil
},