abra/cli/recipe/version.go
decentral1se e1a10723ce
All checks were successful
continuous-integration/drone/push Build is passing
refactor: de-indent and error handle up front
2021-09-06 00:45:29 +02:00

46 lines
1.0 KiB
Go

package recipe
import (
"coopcloud.tech/abra/cli/formatter"
"coopcloud.tech/abra/cli/internal"
"coopcloud.tech/abra/pkg/catalogue"
"github.com/sirupsen/logrus"
"github.com/urfave/cli/v2"
)
var recipeVersionCommand = &cli.Command{
Name: "versions",
Usage: "List recipe versions",
Aliases: []string{"v"},
ArgsUsage: "<recipe>",
Action: func(c *cli.Context) error {
recipe := internal.ValidateRecipe(c)
catalogue, err := catalogue.ReadRecipeCatalogue()
if err != nil {
logrus.Fatal(err)
return nil
}
rec, ok := catalogue[recipe]
if !ok {
logrus.Fatalf("'%s' recipe doesn't exist?", recipe)
}
tableCol := []string{"Version", "Service", "Image", "Digest"}
table := formatter.CreateTable(tableCol)
for version := range rec.Versions {
for service := range rec.Versions[version] {
meta := rec.Versions[version][service]
table.Append([]string{version, service, meta.Image, meta.Digest})
}
}
table.SetAutoMergeCells(true)
table.Render()
return nil
},
}