forked from toolshed/abra
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]
|
recipeName = args[0]
|
||||||
}
|
}
|
||||||
|
|
||||||
if recipeName == "" && !NoInput {
|
var recipes []string
|
||||||
var recipes []string
|
|
||||||
|
|
||||||
catl, err := recipe.ReadRecipeCatalogue(Offline)
|
catl, err := recipe.ReadRecipeCatalogue(Offline)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
knownRecipes := make(map[string]bool)
|
knownRecipes := make(map[string]bool)
|
||||||
for name := range catl {
|
for name := range catl {
|
||||||
knownRecipes[name] = true
|
knownRecipes[name] = true
|
||||||
}
|
}
|
||||||
|
|
||||||
localRecipes, err := recipe.GetRecipesLocal()
|
localRecipes, err := recipe.GetRecipesLocal()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Debugf("can't read local recipes: %s", err)
|
log.Debugf("can't read local recipes: %s", err)
|
||||||
} else {
|
} else {
|
||||||
for _, recipeLocal := range localRecipes {
|
for _, recipeLocal := range localRecipes {
|
||||||
if _, ok := knownRecipes[recipeLocal]; !ok {
|
if _, ok := knownRecipes[recipeLocal]; !ok {
|
||||||
knownRecipes[recipeLocal] = true
|
knownRecipes[recipeLocal] = true
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
for recipeName := range knownRecipes {
|
for recipeName := range knownRecipes {
|
||||||
recipes = append(recipes, recipeName)
|
recipes = append(recipes, recipeName)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if recipeName == "" && !NoInput {
|
||||||
prompt := &survey.Select{
|
prompt := &survey.Select{
|
||||||
Message: "Select recipe",
|
Message: "Select recipe",
|
||||||
Options: recipes,
|
Options: recipes,
|
||||||
@ -58,11 +58,15 @@ func ValidateRecipe(args []string, cmdName string) recipe.Recipe {
|
|||||||
log.Fatal("no recipe name provided")
|
log.Fatal("no recipe name provided")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if _, ok := knownRecipes[recipeName]; !ok {
|
||||||
|
log.Fatalf("no recipe '%s' exists?", recipeName)
|
||||||
|
}
|
||||||
|
|
||||||
chosenRecipe := recipe.Get(recipeName)
|
chosenRecipe := recipe.Get(recipeName)
|
||||||
err := chosenRecipe.EnsureExists()
|
if err := chosenRecipe.EnsureExists(); err != nil {
|
||||||
if err != nil {
|
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err = chosenRecipe.GetComposeConfig(nil)
|
_, err = chosenRecipe.GetComposeConfig(nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if cmdName == "generate" {
|
if cmdName == "generate" {
|
||||||
|
Reference in New Issue
Block a user