refactor: always validate recipe
This can slow things significantly down by requiring the catalogue and if you don't have that, cause a slow `git clone`. However, the current behvaiour is very confusing because it never actually checks if what the user passes is actually a recipe. `abra recipe fetch DOESNTEXIST` gives a better error to the user now. I'm hoping we can speed up the catalogue handling at some point.
This commit is contained in:
@ -17,34 +17,34 @@ func ValidateRecipe(args []string, cmdName string) recipe.Recipe {
|
||||
recipeName = args[0]
|
||||
}
|
||||
|
||||
if recipeName == "" && !NoInput {
|
||||
var recipes []string
|
||||
var recipes []string
|
||||
|
||||
catl, err := recipe.ReadRecipeCatalogue(Offline)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
catl, err := recipe.ReadRecipeCatalogue(Offline)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
knownRecipes := make(map[string]bool)
|
||||
for name := range catl {
|
||||
knownRecipes[name] = true
|
||||
}
|
||||
knownRecipes := make(map[string]bool)
|
||||
for name := range catl {
|
||||
knownRecipes[name] = true
|
||||
}
|
||||
|
||||
localRecipes, err := recipe.GetRecipesLocal()
|
||||
if err != nil {
|
||||
log.Debugf("can't read local recipes: %s", err)
|
||||
} else {
|
||||
for _, recipeLocal := range localRecipes {
|
||||
if _, ok := knownRecipes[recipeLocal]; !ok {
|
||||
knownRecipes[recipeLocal] = true
|
||||
}
|
||||
localRecipes, err := recipe.GetRecipesLocal()
|
||||
if err != nil {
|
||||
log.Debugf("can't read local recipes: %s", err)
|
||||
} else {
|
||||
for _, recipeLocal := range localRecipes {
|
||||
if _, ok := knownRecipes[recipeLocal]; !ok {
|
||||
knownRecipes[recipeLocal] = true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for recipeName := range knownRecipes {
|
||||
recipes = append(recipes, recipeName)
|
||||
}
|
||||
for recipeName := range knownRecipes {
|
||||
recipes = append(recipes, recipeName)
|
||||
}
|
||||
|
||||
if recipeName == "" && !NoInput {
|
||||
prompt := &survey.Select{
|
||||
Message: "Select recipe",
|
||||
Options: recipes,
|
||||
@ -58,11 +58,15 @@ func ValidateRecipe(args []string, cmdName string) recipe.Recipe {
|
||||
log.Fatal("no recipe name provided")
|
||||
}
|
||||
|
||||
if _, ok := knownRecipes[recipeName]; !ok {
|
||||
log.Fatalf("no recipe '%s' exists?", recipeName)
|
||||
}
|
||||
|
||||
chosenRecipe := recipe.Get(recipeName)
|
||||
err := chosenRecipe.EnsureExists()
|
||||
if err != nil {
|
||||
if err := chosenRecipe.EnsureExists(); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
_, err = chosenRecipe.GetComposeConfig(nil)
|
||||
if err != nil {
|
||||
if cmdName == "generate" {
|
||||
|
Reference in New Issue
Block a user