From 1c7863fe499b2028104ed8d7fb17cf4b473cbfb7 Mon Sep 17 00:00:00 2001 From: Brian Buller Date: Tue, 12 May 2015 16:02:39 -0500 Subject: [PATCH] A little smoothing out --- boltprint.go | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/boltprint.go b/boltprint.go index 8b801c0..d3c6b1d 100644 --- a/boltprint.go +++ b/boltprint.go @@ -13,15 +13,24 @@ func main() { fmt.Println("Usage: printbolt [build]") os.Exit(1) } - db, err := bolt.Open(args[0], 0600, nil) + filename := args[0] + + if len(args) > 1 && args[1] == "build" { + if _, err := os.Stat(filename); err == nil { + fmt.Printf("Cowardly refusing to overwrite file: %s\n", filename) + return + } + } + + db, err := bolt.Open(filename, 0600, nil) if err != nil { fmt.Println(err) } defer db.Close() if len(args) > 1 { - if args[1] == "gentest" { - // createTestDatabase(db) + if args[1] == "build" { + createTestDatabase(db) } else if args[1] == "json" { jsonDatabase(db) }