From 27f68b1dc590bf6cf7a7235ae0f7013f40869c98 Mon Sep 17 00:00:00 2001 From: decentral1se Date: Sat, 28 Dec 2024 20:55:25 +0100 Subject: [PATCH] refactor!: recipe fetch [recipe | --all] See https://git.coopcloud.tech/toolshed/organising/issues/639 --- cli/recipe/fetch.go | 27 ++++++++++++++++++++++++--- tests/integration/recipe_fetch.bats | 12 +++++++++++- 2 files changed, 35 insertions(+), 4 deletions(-) diff --git a/cli/recipe/fetch.go b/cli/recipe/fetch.go index 1a37c42c..7840dc0f 100644 --- a/cli/recipe/fetch.go +++ b/cli/recipe/fetch.go @@ -10,10 +10,9 @@ import ( ) var RecipeFetchCommand = &cobra.Command{ - Use: "fetch [recipe] [flags]", + Use: "fetch [recipe | --all] [flags]", Aliases: []string{"f"}, - Short: "Fetch recipe(s)", - Long: "Retrieves all recipes if no [recipe] argument is passed.", + Short: "Clone recipe(s) locally", Args: cobra.RangeArgs(0, 1), ValidArgsFunction: func( cmd *cobra.Command, @@ -27,6 +26,14 @@ var RecipeFetchCommand = &cobra.Command{ recipeName = args[0] } + if recipeName == "" && !fetchAllRecipes { + log.Fatal("missing [recipe] or --all/-a") + } + + if recipeName != "" && fetchAllRecipes { + log.Fatal("cannot use [recipe] and --all/-a together") + } + if recipeName != "" { r := internal.ValidateRecipe(args, cmd.Name()) if err := r.Ensure(false, false); err != nil { @@ -50,3 +57,17 @@ var RecipeFetchCommand = &cobra.Command{ } }, } + +var ( + fetchAllRecipes bool +) + +func init() { + RecipeFetchCommand.Flags().BoolVarP( + &fetchAllRecipes, + "all", + "a", + false, + "fetch all recipes", + ) +} diff --git a/tests/integration/recipe_fetch.bats b/tests/integration/recipe_fetch.bats index d2415355..8e296760 100644 --- a/tests/integration/recipe_fetch.bats +++ b/tests/integration/recipe_fetch.bats @@ -11,7 +11,7 @@ setup() { assert_success assert_not_exists "$ABRA_DIR/recipes/matrix-synapse" - run $ABRA recipe fetch + run $ABRA recipe fetch --all assert_success assert_exists "$ABRA_DIR/recipes/matrix-synapse" } @@ -25,3 +25,13 @@ setup() { assert_success assert_exists "$ABRA_DIR/recipes/matrix-synapse" } + +@test "error if missing args/flags" { + run $ABRA recipe fetch + assert_failure +} + +@test "error if single recipe and --all" { + run $ABRA recipe fetch matrix-synapse --all + assert_failure +}