-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathset.go
58 lines (47 loc) · 935 Bytes
/
set.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
51
52
53
54
55
56
57
58
package main
import (
"fmt"
"os"
"github.com/codegangsta/cli"
)
func set(c *cli.Context) {
db, err := getDB()
if err != nil {
Print(c, "Cannot open database file:", dbPath)
os.Exit(1)
}
defer db.Close()
tx, err := db.Begin(true)
if err != nil {
Print(c, err.Error())
os.Exit(1)
}
defer tx.Rollback()
b, err := getBucket(tx, []byte("settings"))
if err != nil {
Print(c, err.Error())
os.Exit(1)
}
candidate := c.Args().Get(0)
if len(candidate) == 0 {
Print(c, "No version given")
os.Exit(1)
}
if candidate != "system" {
if err := checkCandidate(tx, candidate); err != nil {
Print(c, err.Error())
os.Exit(1)
}
}
if c.Bool("default") {
b.Put([]byte("default"), []byte(candidate))
if err := tx.Commit(); err != nil {
fmt.Println("Cannot save settings")
os.Exit(1)
}
printEnv(candidate)
Print(c, "Now,", candidate, "default ruby")
} else {
printEnv(candidate)
}
}