-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathls.go
47 lines (41 loc) · 973 Bytes
/
ls.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package cli
import (
"fmt"
"io/ioutil"
"strings"
"github.com/Masterminds/semver"
"github.com/k0kubun/go-ansi"
"github.com/urfave/cli"
)
func list(ctx *cli.Context) (err error) {
infos, err := ioutil.ReadDir(versionsDir)
if err != nil || len(infos) <= 0 {
fmt.Printf("No version installed yet\n\n")
return nil
}
items := make([]*semver.Version, 0, len(infos))
for i := range infos {
if !infos[i].IsDir() {
continue
}
vname := infos[i].Name()
var idx int
if strings.Contains(vname, "alpha") {
idx = strings.Index(vname, "alpha")
} else if strings.Contains(vname, "beta") {
idx = strings.Index(vname, "beta")
} else if strings.Contains(vname, "rc") {
idx = strings.Index(vname, "rc")
}
if idx > 0 {
vname = vname[:idx] + "-" + vname[idx:]
}
v, err := semver.NewVersion(vname)
if err != nil || v == nil {
continue
}
items = append(items, v)
}
render(inuse(goroot), items, ansi.NewAnsiStdout())
return nil
}