gvcgo / version-manager

🔥 A general version manager for thousands of SDKs with TUI inspired by lazygit. No need to remember any commands. Less bugs.
https://vdocs.vmr.us.kg
MIT License
835 stars 31 forks source link

Sort beta/RC versions before release versions #104

Closed rasa closed 2 months ago

rasa commented 2 months ago

Numeric suffixes sort ok:

 1.21.12               unarchiver
 1.21.11               unarchiver
 1.21.10               unarchiver
 1.21.9                unarchiver
 1.21.8                unarchiver

But alphanumeric suffixes don't:

 1.23rc2               unarchiver
 1.23rc1               unarchiver
 1.23.0                unarchiver
 1.22.6                unarchiver

This would be preferable:

 1.23.0                unarchiver
 1.23rc2               unarchiver
 1.23rc1               unarchiver
 1.22.6                unarchiver
 1.22.5                unarchiver
 1.22.4                unarchiver
 1.22.3                unarchiver
 1.22.2                unarchiver
 1.22.1                unarchiver
 1.22.0                unarchiver
 1.22rc2               unarchiver
 1.22rc1               unarchiver
 1.21.13               unarchiver
moqsien commented 2 months ago

We cannot find a general algorithm for all SDKs in sorting beta or rc versions.

And also it hardly matters, as the disorder is very tiny.

It isn’t worth the trouble.

rasa commented 2 months ago

@moqsien https://go.dev/play/p/Z0BNYudoRPj

package main

import (
    "fmt"
    "go/version"
    "slices"
)

func main() {
    vers := []string{
        "go1.23rc2",
        "go1.23rc1",
        "go1.23.0",
        "go1.22rc2",
        "go1.22rc1",
        "go1.22.1",
        "go1.22.0",
        "go1.21.13",
    }
    slices.SortFunc(vers, func(a, b string) int {
        return version.Compare(a, b)
    })
    fmt.Printf("%v\n", vers)
}

[go1.21.13 go1.22rc1 go1.22rc2 go1.22.0 go1.22.1 go1.23rc1 go1.23rc2 go1.23.0]

moqsien commented 2 months ago

So, how about JDK, Python, Nodejs, bun, gcc, clang, kotlin, scala, etc?

Note that, we are not only for go.

rasa commented 2 months ago

So, how about JDK, Python, Nodejs, bun, gcc, clang, kotlin, scala, etc?

Note that, we are not only for go.

Understood. We would need to prefix "go" to the versions, sort, then remove the prefix.

I will provide a PR, if you point to where in the code we would add this.

rasa commented 2 months ago

Or perhaps we use https://pkg.go.dev/golang.org/x/mod/semver#Compare instead?

moqsien commented 2 months ago

If you still wanna work on this, you can refer to sort.go.