2015-05-18 14:47:08 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2017-10-12 04:47:00 +00:00
|
|
|
"flag"
|
2015-05-18 14:47:08 +00:00
|
|
|
"fmt"
|
|
|
|
"os"
|
2015-09-17 16:49:57 +00:00
|
|
|
|
|
|
|
"github.com/boltdb/bolt"
|
|
|
|
"github.com/nsf/termbox-go"
|
2015-05-18 14:47:08 +00:00
|
|
|
)
|
|
|
|
|
2015-09-17 16:49:57 +00:00
|
|
|
/*
|
|
|
|
ProgramName is the name of the program
|
|
|
|
*/
|
2017-04-04 21:08:08 +00:00
|
|
|
var ProgramName = "boltbrowser"
|
2015-05-18 14:47:08 +00:00
|
|
|
|
2017-04-04 21:19:07 +00:00
|
|
|
var databaseFiles []string
|
2015-05-18 14:47:08 +00:00
|
|
|
var db *bolt.DB
|
|
|
|
var memBolt *BoltDB
|
|
|
|
|
2017-04-04 21:41:15 +00:00
|
|
|
var currentFilename string
|
|
|
|
|
2017-10-12 04:47:00 +00:00
|
|
|
func init() {
|
|
|
|
flag.Usage = func() {
|
|
|
|
fmt.Fprintf(os.Stdout, "Usage: %s <filename(s)>\n", ProgramName)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-05-18 14:47:08 +00:00
|
|
|
func main() {
|
|
|
|
var err error
|
|
|
|
|
2017-10-12 04:47:00 +00:00
|
|
|
flag.Parse()
|
|
|
|
|
|
|
|
if flag.NArg() == 0 {
|
|
|
|
flag.Usage()
|
2015-05-18 14:47:08 +00:00
|
|
|
os.Exit(1)
|
|
|
|
}
|
|
|
|
|
|
|
|
err = termbox.Init()
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
defer termbox.Close()
|
|
|
|
style := defaultStyle()
|
|
|
|
termbox.SetOutputMode(termbox.Output256)
|
|
|
|
|
2017-10-12 04:47:00 +00:00
|
|
|
databaseFiles := flag.Args()
|
2017-04-04 21:19:07 +00:00
|
|
|
for _, databaseFile := range databaseFiles {
|
2017-04-04 21:41:15 +00:00
|
|
|
currentFilename = databaseFile
|
2017-04-04 21:19:07 +00:00
|
|
|
db, err = bolt.Open(databaseFile, 0600, nil)
|
|
|
|
if err != nil {
|
2017-04-05 03:31:40 +00:00
|
|
|
if len(databaseFiles) > 1 {
|
|
|
|
mainLoop(nil, style)
|
|
|
|
continue
|
|
|
|
} else {
|
|
|
|
termbox.Close()
|
|
|
|
fmt.Printf("Error reading file: %q\n", err.Error())
|
|
|
|
os.Exit(111)
|
|
|
|
}
|
2017-04-04 21:19:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// First things first, load the database into memory
|
|
|
|
memBolt.refreshDatabase()
|
2017-05-18 13:17:58 +00:00
|
|
|
// Kick off the UI loop
|
2017-04-04 21:19:07 +00:00
|
|
|
mainLoop(memBolt, style)
|
|
|
|
defer db.Close()
|
|
|
|
}
|
2016-05-05 19:50:04 +00:00
|
|
|
}
|