mirror of
https://github.com/kairos-io/kairos-agent.git
synced 2025-04-27 11:21:44 +00:00
bug: Fix version list (#1323)
* 🐛 Fix version list First version in the list is the latest one. Alos moves the check for same version above the current place, so it can check before asking if you want to update to the same version Signed-off-by: Itxaka <itxaka.garcia@spectrocloud.com> * 🌱 Rework versioning for upgrade Use the semver lib to parse the versions into a proper collection where it can be parsed and versions compared and sorted properly Signed-off-by: Itxaka <itxaka.garcia@spectrocloud.com> * 🤖 lint Signed-off-by: Itxaka <itxaka.garcia@spectrocloud.com> --------- Signed-off-by: Itxaka <itxaka.garcia@spectrocloud.com>
This commit is contained in:
parent
98ec3aa12c
commit
c78fee6016
@ -2,8 +2,11 @@ package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"github.com/kairos-io/kairos/v2/internal/agent"
|
||||
"github.com/kairos-io/kairos/v2/internal/bus"
|
||||
@ -12,16 +15,37 @@ import (
|
||||
"github.com/kairos-io/kairos-sdk/bundles"
|
||||
"github.com/kairos-io/kairos-sdk/machine"
|
||||
"github.com/kairos-io/kairos-sdk/state"
|
||||
"github.com/kairos-io/kairos-sdk/utils"
|
||||
"github.com/kairos-io/kairos/v2/internal/common"
|
||||
"github.com/kairos-io/kairos/v2/pkg/config"
|
||||
"github.com/kairos-io/kairos/v2/pkg/config/collector"
|
||||
|
||||
"github.com/Masterminds/semver/v3"
|
||||
"github.com/urfave/cli/v2"
|
||||
"gopkg.in/yaml.v3"
|
||||
)
|
||||
|
||||
var configScanDir = []string{"/oem", "/usr/local/cloud-config", "/run/initramfs/live"}
|
||||
|
||||
// ReleasesToOutput gets a semver.Collection and outputs it in the given format
|
||||
// Only used here.
|
||||
func ReleasesToOutput(rels semver.Collection, output string) []string {
|
||||
// Set them back to their original version number with the v in front
|
||||
var stringRels []string
|
||||
for _, v := range rels {
|
||||
stringRels = append(stringRels, v.Original())
|
||||
}
|
||||
switch strings.ToLower(output) {
|
||||
case "yaml":
|
||||
d, _ := yaml.Marshal(stringRels)
|
||||
return []string{string(d)}
|
||||
case "json":
|
||||
d, _ := json.Marshal(stringRels)
|
||||
return []string{string(d)}
|
||||
default:
|
||||
return stringRels
|
||||
}
|
||||
}
|
||||
|
||||
var cmds = []*cli.Command{
|
||||
{
|
||||
Name: "upgrade",
|
||||
@ -71,7 +95,7 @@ See https://kairos.io/docs/upgrade/manual/ for documentation.
|
||||
Description: `List all available releases versions`,
|
||||
Action: func(c *cli.Context) error {
|
||||
releases := agent.ListReleases()
|
||||
list := utils.ListToOutput(releases, c.String("output"))
|
||||
list := ReleasesToOutput(releases, c.String("output"))
|
||||
for _, i := range list {
|
||||
fmt.Println(i)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user