57 lines
1.3 KiB
Go
57 lines
1.3 KiB
Go
package recipe
|
|
|
|
import (
|
|
"coopcloud.tech/abra/cli/internal"
|
|
"coopcloud.tech/abra/pkg/autocomplete"
|
|
"coopcloud.tech/abra/pkg/formatter"
|
|
recipePkg "coopcloud.tech/abra/pkg/recipe"
|
|
"github.com/sirupsen/logrus"
|
|
"github.com/urfave/cli"
|
|
)
|
|
|
|
var recipeVersionCommand = cli.Command{
|
|
Name: "versions",
|
|
Aliases: []string{"v"},
|
|
Usage: "List recipe versions",
|
|
ArgsUsage: "<recipe>",
|
|
Flags: []cli.Flag{
|
|
internal.DebugFlag,
|
|
},
|
|
Before: internal.SubCommandBefore,
|
|
BashComplete: autocomplete.RecipeNameComplete,
|
|
Action: func(c *cli.Context) error {
|
|
recipe := internal.ValidateRecipe(c, false)
|
|
|
|
catalogue, err := recipePkg.ReadRecipeCatalogue()
|
|
if err != nil {
|
|
logrus.Fatal(err)
|
|
}
|
|
|
|
recipeMeta, ok := catalogue[recipe.Name]
|
|
if !ok {
|
|
logrus.Fatalf("%s recipe doesn't exist?", recipe.Name)
|
|
}
|
|
|
|
tableCol := []string{"Version", "Service", "Image", "Tag"}
|
|
table := formatter.CreateTable(tableCol)
|
|
|
|
for i := len(recipeMeta.Versions) - 1; i >= 0; i-- {
|
|
for tag, meta := range recipeMeta.Versions[i] {
|
|
for service, serviceMeta := range meta {
|
|
table.Append([]string{tag, service, serviceMeta.Image, serviceMeta.Tag})
|
|
}
|
|
}
|
|
}
|
|
|
|
table.SetAutoMergeCells(true)
|
|
|
|
if table.NumLines() > 0 {
|
|
table.Render()
|
|
} else {
|
|
logrus.Fatalf("%s has no published versions?", recipe.Name)
|
|
}
|
|
|
|
return nil
|
|
},
|
|
}
|