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

See toolshed/organising#639
This commit is contained in:
2024-12-28 20:55:25 +01:00
parent a0da5299fe
commit 27f68b1dc5
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",
)
}