forked from toolshed/abra
feat: generate versions for catalogue also
Closes coop-cloud/organising#179.
This commit is contained in:
@ -2,6 +2,7 @@ package catalogue
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"path"
|
||||
|
||||
@ -45,11 +46,22 @@ var CatalogueSkipList = map[string]bool{
|
||||
}
|
||||
|
||||
var catalogueGenerateCommand = &cli.Command{
|
||||
Name: "generate",
|
||||
Aliases: []string{"g"},
|
||||
Usage: "Generate a new copy of the catalogue",
|
||||
ArgsUsage: "[<recipe>]",
|
||||
BashComplete: func(c *cli.Context) {},
|
||||
Name: "generate",
|
||||
Aliases: []string{"g"},
|
||||
Usage: "Generate a new copy of the catalogue",
|
||||
ArgsUsage: "[<recipe>]",
|
||||
BashComplete: func(c *cli.Context) {
|
||||
catl, err := catalogue.ReadRecipeCatalogue()
|
||||
if err != nil {
|
||||
logrus.Warn(err)
|
||||
}
|
||||
if c.NArg() > 0 {
|
||||
return
|
||||
}
|
||||
for name := range catl {
|
||||
fmt.Println(name)
|
||||
}
|
||||
},
|
||||
Action: func(c *cli.Context) error {
|
||||
recipeName := c.Args().First()
|
||||
|
||||
@ -60,18 +72,18 @@ var catalogueGenerateCommand = &cli.Command{
|
||||
|
||||
logrus.Debugf("ensuring '%v' recipe(s) are locally present and up-to-date", len(repos))
|
||||
|
||||
bar := formatter.CreateProgressbar(len(repos), "retrieving recipes...")
|
||||
retrieveBar := formatter.CreateProgressbar(len(repos), "retrieving recipes...")
|
||||
ch := make(chan string, len(repos))
|
||||
for _, repoMeta := range repos {
|
||||
go func(rm catalogue.RepoMeta) {
|
||||
if recipeName != "" && recipeName != rm.Name {
|
||||
ch <- rm.Name
|
||||
bar.Add(1)
|
||||
retrieveBar.Add(1)
|
||||
return
|
||||
}
|
||||
if _, exists := CatalogueSkipList[rm.Name]; exists {
|
||||
ch <- rm.Name
|
||||
bar.Add(1)
|
||||
retrieveBar.Add(1)
|
||||
return
|
||||
}
|
||||
|
||||
@ -86,7 +98,7 @@ var catalogueGenerateCommand = &cli.Command{
|
||||
}
|
||||
|
||||
ch <- rm.Name
|
||||
bar.Add(1)
|
||||
retrieveBar.Add(1)
|
||||
}(repoMeta)
|
||||
}
|
||||
|
||||
@ -95,14 +107,23 @@ var catalogueGenerateCommand = &cli.Command{
|
||||
}
|
||||
|
||||
catl := make(catalogue.RecipeCatalogue)
|
||||
catlBar := formatter.CreateProgressbar(len(repos), "generating catalogue...")
|
||||
for _, recipeMeta := range repos {
|
||||
if recipeName != "" && recipeName != recipeMeta.Name {
|
||||
catlBar.Add(1)
|
||||
continue
|
||||
}
|
||||
|
||||
if _, exists := CatalogueSkipList[recipeMeta.Name]; exists {
|
||||
catlBar.Add(1)
|
||||
continue
|
||||
}
|
||||
|
||||
versions, err := catalogue.GetRecipeVersions(recipeMeta.Name)
|
||||
if err != nil {
|
||||
logrus.Fatal(err)
|
||||
}
|
||||
|
||||
catl[recipeMeta.Name] = catalogue.RecipeMeta{
|
||||
Name: recipeMeta.Name,
|
||||
Repository: recipeMeta.CloneURL,
|
||||
@ -110,10 +131,11 @@ var catalogueGenerateCommand = &cli.Command{
|
||||
DefaultBranch: recipeMeta.DefaultBranch,
|
||||
Description: recipeMeta.Description,
|
||||
Website: recipeMeta.Website,
|
||||
// Versions: ..., // FIXME: once the new versions work goes down
|
||||
Versions: versions,
|
||||
// Category: ..., // FIXME: once we sort out the machine-readable catalogue interface
|
||||
// Features: ..., // FIXME: once we figure out the machine-readable catalogue interface
|
||||
}
|
||||
catlBar.Add(1)
|
||||
}
|
||||
|
||||
recipesJSON, err := json.MarshalIndent(catl, "", " ")
|
||||
@ -125,7 +147,7 @@ var catalogueGenerateCommand = &cli.Command{
|
||||
logrus.Fatal(err)
|
||||
}
|
||||
|
||||
logrus.Debugf("generated new recipe catalogue in '%s'", config.APPS_JSON)
|
||||
logrus.Infof("generated new recipe catalogue in '%s'", config.APPS_JSON)
|
||||
|
||||
return nil
|
||||
},
|
||||
|
Reference in New Issue
Block a user