feat: filter recipes list
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
This commit is contained in:
parent
37e48f262b
commit
3eef1e8587
|
@ -4,6 +4,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"sort"
|
"sort"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"coopcloud.tech/abra/cli/formatter"
|
"coopcloud.tech/abra/cli/formatter"
|
||||||
"coopcloud.tech/abra/pkg/catalogue"
|
"coopcloud.tech/abra/pkg/catalogue"
|
||||||
|
@ -11,10 +12,22 @@ import (
|
||||||
"github.com/urfave/cli/v2"
|
"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{
|
var recipeListCommand = &cli.Command{
|
||||||
Name: "list",
|
Name: "list",
|
||||||
Usage: "List available recipes",
|
Usage: "List available recipes",
|
||||||
Aliases: []string{"ls"},
|
Aliases: []string{"ls"},
|
||||||
|
Flags: []cli.Flag{
|
||||||
|
patternFlag,
|
||||||
|
},
|
||||||
Action: func(c *cli.Context) error {
|
Action: func(c *cli.Context) error {
|
||||||
catl, err := catalogue.ReadRecipeCatalogue()
|
catl, err := catalogue.ReadRecipeCatalogue()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -24,7 +37,7 @@ var recipeListCommand = &cli.Command{
|
||||||
recipes := catl.Flatten()
|
recipes := catl.Flatten()
|
||||||
sort.Sort(catalogue.ByRecipeName(recipes))
|
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)
|
table := formatter.CreateTable(tableCol)
|
||||||
|
|
||||||
for _, recipe := range recipes {
|
for _, recipe := range recipes {
|
||||||
|
@ -35,13 +48,24 @@ var recipeListCommand = &cli.Command{
|
||||||
recipe.Features.Healthcheck,
|
recipe.Features.Healthcheck,
|
||||||
recipe.Features.Backups,
|
recipe.Features.Backups,
|
||||||
recipe.Features.Email,
|
recipe.Features.Email,
|
||||||
|
recipe.Features.Tests,
|
||||||
recipe.Features.SSO,
|
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.SetCaption(true, fmt.Sprintf("total recipes: %v", len(recipes)))
|
||||||
table.Render()
|
|
||||||
|
if table.NumLines() > 0 {
|
||||||
|
table.Render()
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in New Issue