-
Notifications
You must be signed in to change notification settings - Fork 2
/
BoltInspector.go
90 lines (80 loc) · 1.76 KB
/
BoltInspector.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
package main
import (
"bufio"
"os"
"fmt"
"github.com/boltdb/bolt"
"log"
"path/filepath"
"strings"
)
// full path to database; just the file name
var path,filename = "", ""
// var for root bucket
var root = bckt{[]string{"~"}}
// path to current bucket inside the database; "~" is root
var currentBucket = bckt{[]string{"~"}}
func main() {
// Get the database path from the user and verify it exists
for {
fmt.Println()
fmt.Print("Database to Read (or exit): ")
scan := bufio.NewScanner(os.Stdin)
scan.Scan()
DBPath := scan.Text()
ex,_ := exists(DBPath)
if DBPath=="exit" {
fmt.Println("Exiting...")
os.Exit(0)
return
} else if !ex {
fmt.Print("[Error] The specified file does not exist.\n")
} else {
path = DBPath
break
}
}
// verify that bolt can open the database
db, err := bolt.Open(path, 0600, nil)
if err != nil {
log.Fatal(err)
}
db.Close()
// set the filename var
_, filename = filepath.Split(path)
// main loop of the script
for {
fmt.Print("["+filename+"] ("+currentBucket.bucketString()+") $>")
scan := bufio.NewScanner(os.Stdin)
scan.Scan()
cmd := strings.SplitN(scan.Text()," ",2)
if cmd[0]=="exit" {
fmt.Println("Exiting...")
break
} else if cmd[0]=="help" {
help(cmd)
} else if cmd[0]=="list" {
list(cmd)
} else if cmd[0]=="rlist"{
rlist(cmd)
} else if cmd[0]=="cd"{
cd(cmd)
} else if cmd[0]=="print"{
print(cmd)
} else if cmd[0]=="write"{
write(cmd)
} else if cmd[0]=="bucket"{
bucket(cmd)
} else if cmd[0]=="delete"{
delete(cmd)
} else if cmd[0]=="empty"{
emptyBucket(cmd)
} else if cmd[0]=="copy"{
copy(cmd,false)
} else if cmd[0]=="move"{
copy(cmd,true)
} else {
fmt.Println("Unrecognized command. Type \"help\" to see commands")
}
}
}