Add --help flag support

Currently executing `boltbrowser --help` creates a file with name
`--help` in the current working directory, which is counterintuitive.
This commit adds command-line flags support to boltbrowser and changes
it to print out the usage message instead.
This commit is contained in:
Andrew Slotin 2017-10-12 11:47:00 +07:00
parent 3c22c6227b
commit 46e67d5848

View File

@ -1,6 +1,7 @@
package main
import (
"flag"
"fmt"
"os"
@ -19,11 +20,19 @@ 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)
flag.Parse()
if flag.NArg() == 0 {
flag.Usage()
os.Exit(1)
}
@ -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)