From 3eef1e858739954657716c469060d87f38749b8b Mon Sep 17 00:00:00 2001 From: cellarspoon Date: Mon, 27 Dec 2021 11:00:04 +0100 Subject: [PATCH] feat: filter recipes list --- cli/recipe/list.go | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/cli/recipe/list.go b/cli/recipe/list.go index 3e1c1b2b..c8d8d0a5 100644 --- a/cli/recipe/list.go +++ b/cli/recipe/list.go @@ -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 },