Merge pull request #19 from andrewslotin/add_flags_support

Add flags support
Add *.db to .gitignore
Exit with status code 2 (command misuse) if no files were given
This commit is contained in:
Brian Buller 2017-10-12 06:57:08 -05:00 committed by GitHub
commit e903cbcea6
2 changed files with 14 additions and 4 deletions

1
.gitignore vendored
View File

@ -28,3 +28,4 @@ boltbrowser
# Test Database
test.db
*.db

View File

@ -1,6 +1,7 @@
package main
import (
"flag"
"fmt"
"os"
@ -19,12 +20,20 @@ var memBolt *BoltDB
var currentFilename string
func init() {
flag.Usage = func() {
fmt.Fprintf(os.Stdout, "Usage: %s <filename(s)>\n", ProgramName)
}
}
func main() {
var err error
if len(os.Args) < 2 {
fmt.Printf("Usage: %s <filename(s)>\n", ProgramName)
os.Exit(1)
flag.Parse()
if flag.NArg() == 0 {
flag.Usage()
os.Exit(2)
}
err = termbox.Init()
@ -35,7 +44,7 @@ func main() {
style := defaultStyle()
termbox.SetOutputMode(termbox.Output256)
databaseFiles := os.Args[1:]
databaseFiles := flag.Args()
for _, databaseFile := range databaseFiles {
currentFilename = databaseFile
db, err = bolt.Open(databaseFile, 0600, nil)