Merge pull request #10 from aerth/multi

Allow user to open multiple files, for example 'boltbrowser *.db'
This commit is contained in:
Brian Buller 2017-04-04 16:33:16 -05:00 committed by GitHub
commit e83f065faa

View File

@ -13,28 +13,18 @@ ProgramName is the name of the program
*/ */
var ProgramName = "boltbrowser" var ProgramName = "boltbrowser"
var databaseFile string var databaseFiles []string
var db *bolt.DB var db *bolt.DB
var memBolt *BoltDB var memBolt *BoltDB
func main() { func main() {
var err error var err error
if len(os.Args) != 2 { if len(os.Args) < 2 {
fmt.Printf("Usage: %s <filename>\n", ProgramName) fmt.Printf("Usage: %s <filename(s)>\n", ProgramName)
os.Exit(1) os.Exit(1)
} }
databaseFile := os.Args[1]
db, err = bolt.Open(databaseFile, 0600, nil)
if err != nil {
fmt.Printf("Error reading file: %q\n", err.Error())
os.Exit(1)
}
// First things first, load the database into memory
memBolt.refreshDatabase()
err = termbox.Init() err = termbox.Init()
if err != nil { if err != nil {
panic(err) panic(err)
@ -44,6 +34,17 @@ func main() {
style := defaultStyle() style := defaultStyle()
termbox.SetOutputMode(termbox.Output256) termbox.SetOutputMode(termbox.Output256)
databaseFiles := os.Args[1:]
for _, databaseFile := range databaseFiles {
db, err = bolt.Open(databaseFile, 0600, nil)
if err != nil {
fmt.Printf("Error reading file: %q\n", err.Error())
os.Exit(1)
}
// First things first, load the database into memory
memBolt.refreshDatabase()
mainLoop(memBolt, style) mainLoop(memBolt, style)
defer db.Close() defer db.Close()
} }
}