提交 af79f5c2 编写于 作者: C Corey Butler

Sort the output of installed versions using new semver library. Fixes #262.

上级 472411ed
......@@ -4,7 +4,7 @@ SET ORIG=%CD%
REM SET GOPATH=%CD%\src
SET GOBIN=%CD%\bin
SET GOARCH=386
SET version=1.1.5
SET version=1.1.6
REM Get the version number from the setup file
REM for /f "tokens=*" %%i in ('findstr /n . %INNOSETUP% ^| findstr ^4:#define') do set L=%%i
......
#define MyAppName "NVM for Windows"
#define MyAppShortName "nvm"
#define MyAppLCShortName "nvm"
#define MyAppVersion "1.1.5"
#define MyAppVersion "1.1.6"
#define MyAppPublisher "Ecor Ventures LLC"
#define MyAppURL "http://github.com/coreybutler/nvm"
#define MyAppExeName "nvm.exe"
......
......@@ -17,7 +17,7 @@ import (
)
const (
NvmVersion = "1.1.5"
NvmVersion = "1.1.6"
)
type Environment struct {
......@@ -446,6 +446,7 @@ func list(listtype string) {
inuse, a := node.GetCurrentVersion()
v := node.GetInstalled(env.root)
for i := 0; i < len(v); i++ {
version := v[i]
isnode, _ := regexp.MatchString("v",version)
......
......@@ -80,28 +80,56 @@ func IsVersionAvailable(v string) bool {
return false
}
func reverseStringArray(str []string) []string {
for i := 0; i < len(str)/2; i++ {
j := len(str) - i - 1
str[i], str[j] = str[j], str[i]
}
return str
}
func GetInstalled(root string) []string {
list := make([]string,0)
list := make([]semver.Version,0)
files, _ := ioutil.ReadDir(root)
for i := len(files) - 1; i >= 0; i-- {
if files[i].IsDir() {
isnode, _ := regexp.MatchString("v",files[i].Name())
if isnode {
list = append(list,files[i].Name())
currentVersionString := strings.Replace(files[i].Name(), "v", "", 1)
currentVersion, _ := semver.Make(currentVersionString)
list = append(list, currentVersion)
}
}
}
return list
semver.Sort(list)
loggableList := make([]string,0)
for _, version := range list {
loggableList = append(loggableList, "v" + version.String())
}
loggableList = reverseStringArray(loggableList)
return loggableList
}
// Sorting
type BySemanticVersion []string
func (s BySemanticVersion) Len() int {
return len(s)
}
func (s BySemanticVersion) Swap(i, j int) {
s[i], s[j] = s[j], s[i]
}
func (s BySemanticVersion) Less(i, j int) bool {
v1, _ := semver.Make(s[i])
v2, _ := semver.Make(s[j])
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册