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:
commit
e903cbcea6
1
.gitignore
vendored
1
.gitignore
vendored
@ -28,3 +28,4 @@ boltbrowser
|
||||
|
||||
# Test Database
|
||||
test.db
|
||||
*.db
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user