From e6b5fdc30e0398dfe0c08355babf397fb8bfc470 Mon Sep 17 00:00:00 2001 From: Ben Johnson Date: Fri, 11 Apr 2014 13:23:11 -0600 Subject: Add import/export to CLI. This commit adds two new commands: bolt import --input INPUT PATH bolt export PATH This exports the database in a simple, nested, key/value JSON document. Each node in the document has a "key", a "value", and an optional "type". The key and value fields are both base64 encoded. --- cmd/bolt/main_test.go | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) (limited to 'cmd/bolt/main_test.go') diff --git a/cmd/bolt/main_test.go b/cmd/bolt/main_test.go index 51198c8..9b32cc8 100644 --- a/cmd/bolt/main_test.go +++ b/cmd/bolt/main_test.go @@ -10,17 +10,15 @@ import ( ) // open creates and opens a Bolt database in the temp directory. -func open(fn func(*bolt.DB)) { - f, _ := ioutil.TempFile("", "bolt-") - f.Close() - os.Remove(f.Name()) - defer os.RemoveAll(f.Name()) +func open(fn func(*bolt.DB, string)) { + path := tempfile() + defer os.RemoveAll(path) - db, err := bolt.Open(f.Name(), 0600) + db, err := bolt.Open(path, 0600) if err != nil { panic("db open error: " + err.Error()) } - fn(db) + fn(db, path) } // run executes a command against the CLI and returns the output. @@ -29,3 +27,11 @@ func run(args ...string) string { NewApp().Run(args) return strings.TrimSpace(LogBuffer()) } + +// tempfile returns a temporary file path. +func tempfile() string { + f, _ := ioutil.TempFile("", "bolt-") + f.Close() + os.Remove(f.Name()) + return f.Name() +} -- cgit v1.2.3