refactor!: recipe fetch [recipe | --all]

See toolshed/organising#639
This commit is contained in:
decentral1se 2024-12-28 20:55:25 +01:00
parent a0da5299fe
commit 27f68b1dc5
Signed by: decentral1se
GPG Key ID: 03789458B3D0C410
2 changed files with 35 additions and 4 deletions

View File

@ -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",
)
}

View File

@ -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
}