fix: recipe versions lists correctly (also -m)
This commit is contained in:
parent
78b8cf9725
commit
533edbf172
|
@ -1,6 +1,8 @@
|
||||||
package recipe
|
package recipe
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"sort"
|
||||||
|
|
||||||
"coopcloud.tech/abra/cli/internal"
|
"coopcloud.tech/abra/cli/internal"
|
||||||
"coopcloud.tech/abra/pkg/autocomplete"
|
"coopcloud.tech/abra/pkg/autocomplete"
|
||||||
"coopcloud.tech/abra/pkg/formatter"
|
"coopcloud.tech/abra/pkg/formatter"
|
||||||
|
@ -9,6 +11,16 @@ import (
|
||||||
"github.com/urfave/cli"
|
"github.com/urfave/cli"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func sortServiceByName(versions [][]string) func(i, j int) bool {
|
||||||
|
return func(i, j int) bool {
|
||||||
|
// NOTE(d1): corresponds to the `tableCol` definition below
|
||||||
|
if versions[i][1] == "app" {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
var recipeVersionCommand = cli.Command{
|
var recipeVersionCommand = cli.Command{
|
||||||
Name: "versions",
|
Name: "versions",
|
||||||
Aliases: []string{"v"},
|
Aliases: []string{"v"},
|
||||||
|
@ -19,6 +31,7 @@ var recipeVersionCommand = cli.Command{
|
||||||
internal.DebugFlag,
|
internal.DebugFlag,
|
||||||
internal.OfflineFlag,
|
internal.OfflineFlag,
|
||||||
internal.NoInputFlag,
|
internal.NoInputFlag,
|
||||||
|
internal.MachineReadableFlag,
|
||||||
},
|
},
|
||||||
Before: internal.SubCommandBefore,
|
Before: internal.SubCommandBefore,
|
||||||
BashComplete: autocomplete.RecipeNameComplete,
|
BashComplete: autocomplete.RecipeNameComplete,
|
||||||
|
@ -32,28 +45,37 @@ var recipeVersionCommand = cli.Command{
|
||||||
|
|
||||||
recipeMeta, ok := catl[recipe.Name]
|
recipeMeta, ok := catl[recipe.Name]
|
||||||
if !ok {
|
if !ok {
|
||||||
logrus.Fatalf("%s recipe doesn't exist?", recipe.Name)
|
logrus.Fatalf("%s is not published on the catalogue?", recipe.Name)
|
||||||
}
|
}
|
||||||
|
|
||||||
tableCol := []string{"Version", "Service", "Image", "Tag"}
|
if len(recipeMeta.Versions) == 0 {
|
||||||
table := formatter.CreateTable(tableCol)
|
logrus.Fatalf("%s has no catalogue published versions?", recipe.Name)
|
||||||
|
}
|
||||||
|
|
||||||
for i := len(recipeMeta.Versions) - 1; i >= 0; i-- {
|
for i := len(recipeMeta.Versions) - 1; i >= 0; i-- {
|
||||||
for tag, meta := range recipeMeta.Versions[i] {
|
tableCols := []string{"Version", "Service", "Image", "Tag"}
|
||||||
|
table := formatter.CreateTable(tableCols)
|
||||||
|
for version, meta := range recipeMeta.Versions[i] {
|
||||||
|
var versions [][]string
|
||||||
for service, serviceMeta := range meta {
|
for service, serviceMeta := range meta {
|
||||||
table.Append([]string{tag, service, serviceMeta.Image, serviceMeta.Tag})
|
versions = append(versions, []string{version, service, serviceMeta.Image, serviceMeta.Tag})
|
||||||
|
}
|
||||||
|
|
||||||
|
sort.Slice(versions, sortServiceByName(versions))
|
||||||
|
|
||||||
|
for _, version := range versions {
|
||||||
|
table.Append(version)
|
||||||
|
}
|
||||||
|
|
||||||
|
if internal.MachineReadable {
|
||||||
|
table.JSONRender()
|
||||||
|
} else {
|
||||||
|
table.SetAutoMergeCellsByColumnIndex([]int{0})
|
||||||
|
table.Render()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
table.SetAutoMergeCells(true)
|
|
||||||
|
|
||||||
if table.NumLines() > 0 {
|
|
||||||
table.Render()
|
|
||||||
} else {
|
|
||||||
logrus.Fatalf("%s has no published versions?", recipe.Name)
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,3 +10,28 @@ setup() {
|
||||||
assert_success
|
assert_success
|
||||||
assert_output --partial '2.3.2+1.20.3-rootless'
|
assert_output --partial '2.3.2+1.20.3-rootless'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@test "error if not present in catalogue" {
|
||||||
|
run $ABRA recipe versions "$TEST_RECIPE"
|
||||||
|
assert_failure
|
||||||
|
assert_output --partial "is not published on the catalogue"
|
||||||
|
}
|
||||||
|
|
||||||
|
@test "versions listed in correct order" {
|
||||||
|
latestVersion=$(jq -r '.gitea.versions[-1] | keys[0]' < "$ABRA_DIR/catalogue/recipes.json")
|
||||||
|
refute [ -z "$latestVersion" ];
|
||||||
|
|
||||||
|
run bash -c '$ABRA recipe versions gitea --machine | jq -r ".[0].Version" | head -n 1'
|
||||||
|
assert_success
|
||||||
|
assert_output "$latestVersion"
|
||||||
|
}
|
||||||
|
|
||||||
|
@test "app is first service listed" {
|
||||||
|
run bash -c '$ABRA recipe versions gitea --machine | jq -r ".[0].Service" | uniq'
|
||||||
|
assert_success
|
||||||
|
assert_output 'app'
|
||||||
|
|
||||||
|
run bash -c '$ABRA recipe versions gitea --machine | jq -r ".[1].Service" | uniq'
|
||||||
|
assert_success
|
||||||
|
assert_output 'db'
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue