From 0ee2c57c090d913b7f0c59faddd641f574399f39 Mon Sep 17 00:00:00 2001 From: p4u1 Date: Mon, 8 Jan 2024 15:10:26 +0100 Subject: [PATCH] feat: fetch all recipes when no recipe is specified --- cli/recipe/fetch.go | 35 ++++++++++++++++++++++------- tests/integration/recipe_fetch.bats | 12 +++++++++- 2 files changed, 38 insertions(+), 9 deletions(-) diff --git a/cli/recipe/fetch.go b/cli/recipe/fetch.go index acfc1708..68a19144 100644 --- a/cli/recipe/fetch.go +++ b/cli/recipe/fetch.go @@ -3,6 +3,7 @@ package recipe import ( "coopcloud.tech/abra/cli/internal" "coopcloud.tech/abra/pkg/autocomplete" + "coopcloud.tech/abra/pkg/formatter" "coopcloud.tech/abra/pkg/recipe" "github.com/sirupsen/logrus" "github.com/urfave/cli" @@ -17,28 +18,46 @@ var recipeFetchCommand = cli.Command{ Flags: []cli.Flag{ internal.DebugFlag, internal.NoInputFlag, + internal.OfflineFlag, }, Before: internal.SubCommandBefore, BashComplete: autocomplete.RecipeNameComplete, Action: func(c *cli.Context) error { recipeName := c.Args().First() - if recipeName != "" { internal.ValidateRecipe(c) + if err := fetchRecipe(recipeName); err != nil { + logrus.Fatal(err) + } + return nil } - if err := recipe.EnsureExists(recipeName); err != nil { + catalogue, err := recipe.ReadRecipeCatalogue(internal.Offline) + if err != nil { logrus.Fatal(err) } - if err := recipe.EnsureUpToDate(recipeName); err != nil { - logrus.Fatal(err) - } - - if err := recipe.EnsureLatest(recipeName); err != nil { - logrus.Fatal(err) + catlBar := formatter.CreateProgressbar(len(catalogue), "fetching latest recipes...") + for recipeName := range catalogue { + if err := fetchRecipe(recipeName); err != nil { + logrus.Error(err) + } + catlBar.Add(1) } return nil }, } + +func fetchRecipe(recipeName string) error { + if err := recipe.EnsureExists(recipeName); err != nil { + return err + } + if err := recipe.EnsureUpToDate(recipeName); err != nil { + return err + } + if err := recipe.EnsureLatest(recipeName); err != nil { + return err + } + return nil +} diff --git a/tests/integration/recipe_fetch.bats b/tests/integration/recipe_fetch.bats index a64306ab..1cc61e7c 100644 --- a/tests/integration/recipe_fetch.bats +++ b/tests/integration/recipe_fetch.bats @@ -5,7 +5,17 @@ setup() { _common_setup } -@test "recipe fetch" { +@test "recipe fetch all" { + run rm -rf "$ABRA_DIR/recipes/matrix-synapse" + assert_success + assert_not_exists "$ABRA_DIR/recipes/matrix-synapse" + + run $ABRA recipe fetch + assert_success + assert_exists "$ABRA_DIR/recipes/matrix-synapse" +} + +@test "recipe fetch single recipe" { run rm -rf "$ABRA_DIR/recipes/matrix-synapse" assert_success assert_not_exists "$ABRA_DIR/recipes/matrix-synapse"