fix: much hacking, maybe fixed catalogue generation

This commit is contained in:
2021-12-26 04:02:40 +01:00
parent 3f35510507
commit cdc08ae95a
3 changed files with 122 additions and 99 deletions

View File

@ -4,7 +4,6 @@ import (
"encoding/json"
"fmt"
"io/ioutil"
"os"
"path"
"coopcloud.tech/abra/cli/formatter"
@ -104,17 +103,18 @@ A new catalogue copy can be published to the recipes repository by passing the
logrus.Fatal(err)
}
logrus.Debugf("ensuring %v recipe(s) are locally present and up-to-date", len(repos))
var barLength int
var logMsg string
if recipeName != "" {
barLength = 1
logMsg = fmt.Sprintf("ensuring %v recipe is up-to-date", barLength)
} else {
barLength = len(repos)
logMsg = fmt.Sprintf("ensuring %v recipes are up-to-date", barLength)
}
if !internal.SkipUpdates {
logrus.Warnf("ensuring %v recipe(s) are up-to-date", barLength)
logrus.Warn(logMsg)
if err := updateRepositories(repos, recipeName); err != nil {
logrus.Fatal(err)
}
@ -154,6 +154,7 @@ A new catalogue copy can be published to the recipes repository by passing the
Category: category,
Features: features,
}
catlBar.Add(1)
}
@ -162,25 +163,25 @@ A new catalogue copy can be published to the recipes repository by passing the
logrus.Fatal(err)
}
if _, err := os.Stat(config.RECIPES_JSON); err != nil && os.IsNotExist(err) {
if recipeName == "" {
if err := ioutil.WriteFile(config.RECIPES_JSON, recipesJSON, 0764); err != nil {
logrus.Fatal(err)
}
} else {
if recipeName != "" {
catlFS, err := catalogue.ReadRecipeCatalogue()
if err != nil {
logrus.Fatal(err)
}
catlFS[recipeName] = catl[recipeName]
catlFS, err := catalogue.ReadRecipeCatalogue()
if err != nil {
logrus.Fatal(err)
}
updatedRecipesJSON, err := json.MarshalIndent(catlFS, "", " ")
if err != nil {
logrus.Fatal(err)
}
if err := ioutil.WriteFile(config.RECIPES_JSON, updatedRecipesJSON, 0764); err != nil {
logrus.Fatal(err)
}
catlFS[recipeName] = catl[recipeName]
updatedRecipesJSON, err := json.MarshalIndent(catlFS, "", " ")
if err != nil {
logrus.Fatal(err)
}
if err := ioutil.WriteFile(config.RECIPES_JSON, updatedRecipesJSON, 0764); err != nil {
logrus.Fatal(err)
}
}
@ -207,7 +208,6 @@ A new catalogue copy can be published to the recipes repository by passing the
logrus.Fatal(err)
}
}
}
return nil
@ -270,7 +270,7 @@ func updateRepositories(repos catalogue.RepoCatalogue, recipeName string) error
logrus.Fatalf("%s has locally unstaged changes", rm.Name)
}
if err := catalogue.EnsureUpToDate(rm.Name); err != nil {
if err := recipe.EnsureUpToDate(rm.Name); err != nil {
logrus.Fatal(err)
}