feat: fetch all recipes when no recipe is specified
continuous-integration/drone/pr Build is passing Details

This commit is contained in:
p4u1 2024-01-08 15:10:26 +01:00
parent d4727db8f9
commit 0ee2c57c09
2 changed files with 38 additions and 9 deletions

View File

@ -3,6 +3,7 @@ package recipe
import ( import (
"coopcloud.tech/abra/cli/internal" "coopcloud.tech/abra/cli/internal"
"coopcloud.tech/abra/pkg/autocomplete" "coopcloud.tech/abra/pkg/autocomplete"
"coopcloud.tech/abra/pkg/formatter"
"coopcloud.tech/abra/pkg/recipe" "coopcloud.tech/abra/pkg/recipe"
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
"github.com/urfave/cli" "github.com/urfave/cli"
@ -17,28 +18,46 @@ var recipeFetchCommand = cli.Command{
Flags: []cli.Flag{ Flags: []cli.Flag{
internal.DebugFlag, internal.DebugFlag,
internal.NoInputFlag, internal.NoInputFlag,
internal.OfflineFlag,
}, },
Before: internal.SubCommandBefore, Before: internal.SubCommandBefore,
BashComplete: autocomplete.RecipeNameComplete, BashComplete: autocomplete.RecipeNameComplete,
Action: func(c *cli.Context) error { Action: func(c *cli.Context) error {
recipeName := c.Args().First() recipeName := c.Args().First()
if recipeName != "" { if recipeName != "" {
internal.ValidateRecipe(c) 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) logrus.Fatal(err)
} }
if err := recipe.EnsureUpToDate(recipeName); err != nil { catlBar := formatter.CreateProgressbar(len(catalogue), "fetching latest recipes...")
logrus.Fatal(err) for recipeName := range catalogue {
} if err := fetchRecipe(recipeName); err != nil {
logrus.Error(err)
if err := recipe.EnsureLatest(recipeName); err != nil { }
logrus.Fatal(err) catlBar.Add(1)
} }
return nil 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
}

View File

@ -5,7 +5,17 @@ setup() {
_common_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" run rm -rf "$ABRA_DIR/recipes/matrix-synapse"
assert_success assert_success
assert_not_exists "$ABRA_DIR/recipes/matrix-synapse" assert_not_exists "$ABRA_DIR/recipes/matrix-synapse"