fix: sort versions upgrade/rollback/list
All checks were successful
continuous-integration/drone/push Build is passing

See toolshed/organising#649
This commit is contained in:
decentral1se 2024-12-28 23:10:22 +01:00
parent fab93a559a
commit 7ec61c6d03
Signed by: decentral1se
GPG Key ID: 03789458B3D0C410
5 changed files with 24 additions and 13 deletions

View File

@ -173,7 +173,7 @@ Use "--status/-S" flag to query all servers for the live deployment status.`,
stats.LatestCount++
}
} else {
newUpdates = internal.ReverseStringList(newUpdates)
newUpdates = internal.SortVersionsDesc(newUpdates)
appStats.Upgrade = strings.Join(newUpdates, "\n")
stats.UpgradeCount++
}

View File

@ -167,7 +167,7 @@ beforehand.`,
prompt := &survey.Select{
Message: msg,
Options: internal.ReverseStringList(availableDowngrades),
Options: internal.SortVersionsDesc(availableDowngrades),
}
if err := survey.AskOne(prompt, &chosenDowngrade); err != nil {

View File

@ -159,7 +159,7 @@ beforehand.`,
prompt := &survey.Select{
Message: msg,
Options: internal.ReverseStringList(availableUpgrades),
Options: internal.SortVersionsDesc(availableUpgrades),
}
if err := survey.AskOne(prompt, &chosenUpgrade); err != nil {

View File

@ -3,12 +3,14 @@ package internal
import (
"fmt"
"os"
"sort"
"strings"
appPkg "coopcloud.tech/abra/pkg/app"
"coopcloud.tech/abra/pkg/config"
"coopcloud.tech/abra/pkg/formatter"
"coopcloud.tech/abra/pkg/log"
"coopcloud.tech/tagcmp"
"github.com/AlecAivazis/survey/v2"
"github.com/charmbracelet/lipgloss"
dockerClient "github.com/docker/docker/client"
@ -274,3 +276,22 @@ func PostCmds(cl *dockerClient.Client, app appPkg.App, commands string) error {
}
return nil
}
// SortVersionsDesc sorts versions in descending order.
func SortVersionsDesc(versions []string) []string {
var tags []tagcmp.Tag
for _, v := range versions {
parsed, _ := tagcmp.Parse(v) // skips unsupported tags
tags = append(tags, parsed)
}
sort.Sort(tagcmp.ByTagDesc(tags))
var desc []string
for _, t := range tags {
desc = append(desc, t.String())
}
return desc
}

View File

@ -1,10 +0,0 @@
package internal
// ReverseStringList reverses a list of a strings. Roll on Go generics.
func ReverseStringList(strings []string) []string {
for i, j := 0, len(strings)-1; i < j; i, j = i+1, j-1 {
strings[i], strings[j] = strings[j], strings[i]
}
return strings
}