-
Notifications
You must be signed in to change notification settings - Fork 1
/
list.go
50 lines (41 loc) · 884 Bytes
/
list.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
48
49
50
package main
import (
"fmt"
"os"
"github.com/codegangsta/cli"
)
func GetList(c *cli.Context) {
var installedRubies []string
var knownRubies []string
db, err := getDB()
if err != nil {
Print(c, "Cannot open database file:", dbPath)
os.Exit(1)
}
defer db.Close()
tx, err := db.Begin(false)
if err != nil {
fmt.Println(err)
os.Exit(1)
}
defer tx.Rollback()
b := tx.Bucket([]byte("rubies"))
cursor := b.Cursor()
for k, v := cursor.First(); k != nil; k, v = cursor.Next() {
if v != nil && len(v) != 0 {
installedRubies = append(installedRubies, string(k))
} else {
knownRubies = append(knownRubies, string(k))
}
}
fmt.Println("installed rubies:")
for _, ruby := range installedRubies {
fmt.Println(" ", ruby)
}
if c.Bool("known") {
fmt.Println("known rubies:")
for _, ruby := range knownRubies {
fmt.Println(" ", ruby)
}
}
}