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 Database
test.db test.db
*.db

View File

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