-
Notifications
You must be signed in to change notification settings - Fork 1
/
uninstall.go
59 lines (47 loc) · 1 KB
/
uninstall.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
59
package main
import (
"fmt"
"os"
"os/exec"
"github.com/codegangsta/cli"
)
func GetUninstall(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()
candidate := c.Args().Get(0)
if len(candidate) == 0 {
Print(c, "No version given")
os.Exit(1)
}
if err := checkCandidate(tx, candidate); err != nil {
Print(c, err.Error())
os.Exit(1)
}
if err := exec.Command("rm", "-rf", fmt.Sprintf("%s/%s", rubiesDirectory, candidate)).Run(); err != nil {
Print(c, err.Error())
os.Exit(1)
}
if err := exec.Command("rm", "-rf", fmt.Sprintf("%s/%s", gemsDirectory, candidate)).Run(); err != nil {
Print(c, err.Error())
os.Exit(1)
}
if err := updateAvailableRubiesWithTx(tx); err != nil {
Print(c, err.Error())
os.Exit(1)
}
if err := tx.Commit(); err != nil {
Print(c, err.Error())
os.Exit(1)
}
os.Exit(0)
}