diff --git a/api/util/release.go b/api/util/release.go index 445be11..e051ac1 100644 --- a/api/util/release.go +++ b/api/util/release.go @@ -6,9 +6,10 @@ import ( apps "github.com/ninech/apis/apps/v1alpha1" ) -// OrderReleaseList orders the given list of releases, moving the latest -// release to the beginning of the list -func OrderReleaseList(releaseList *apps.ReleaseList) { +// OrderReleaseList orders the given list of releases first by name and then by +// creation timestamp latest to oldest. Reverse reverses the order by creation +// timestamp to oldest to latest. +func OrderReleaseList(releaseList *apps.ReleaseList, reverse bool) { if len(releaseList.Items) <= 1 { return } @@ -21,6 +22,9 @@ func OrderReleaseList(releaseList *apps.ReleaseList) { return applicationNameI < applicationNameJ } - return releaseList.Items[i].CreationTimestampNano < releaseList.Items[j].CreationTimestampNano + if reverse { + return releaseList.Items[i].CreationTimestampNano < releaseList.Items[j].CreationTimestampNano + } + return releaseList.Items[i].CreationTimestampNano > releaseList.Items[j].CreationTimestampNano }) } diff --git a/exec/application.go b/exec/application.go index 2739ab4..74ff41f 100644 --- a/exec/application.go +++ b/exec/application.go @@ -99,7 +99,7 @@ func (cmd *applicationCmd) Run(ctx context.Context, client *api.Client, exec *Cm } func latestAvailableRelease(releases *apps.ReleaseList) *apps.Release { - util.OrderReleaseList(releases) + util.OrderReleaseList(releases, false) for _, release := range releases.Items { if release.Status.AtProvider.ReleaseStatus == apps.ReleaseProcessStatusAvailable { return &release diff --git a/get/releases.go b/get/releases.go index a617a3b..7213818 100644 --- a/get/releases.go +++ b/get/releases.go @@ -38,7 +38,7 @@ func (cmd *releasesCmd) Run(ctx context.Context, client *api.Client, get *Cmd) e return nil } - util.OrderReleaseList(releaseList) + util.OrderReleaseList(releaseList, true) switch get.Output { case full: