aboutsummaryrefslogtreecommitdiff
path: root/cmd/bolt/main.go
diff options
context:
space:
mode:
authorBen Johnson <benbjohnson@yahoo.com>2014-04-11 13:23:11 -0600
committerBen Johnson <benbjohnson@yahoo.com>2014-04-11 14:05:58 -0600
commite6b5fdc30e0398dfe0c08355babf397fb8bfc470 (patch)
tree2210d344b510769e1bbdb7af67d7f0286861fbe3 /cmd/bolt/main.go
parentMerge pull request #122 from mkobetic/benchmark_tweaks (diff)
downloaddedo-e6b5fdc30e0398dfe0c08355babf397fb8bfc470.tar.gz
dedo-e6b5fdc30e0398dfe0c08355babf397fb8bfc470.tar.xz
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.
Diffstat (limited to 'cmd/bolt/main.go')
-rw-r--r--cmd/bolt/main.go26
1 files changed, 26 insertions, 0 deletions
diff --git a/cmd/bolt/main.go b/cmd/bolt/main.go
index ff3c1bf..1930e7d 100644
--- a/cmd/bolt/main.go
+++ b/cmd/bolt/main.go
@@ -2,6 +2,7 @@ package main
import (
"bytes"
+ "encoding/json"
"fmt"
"log"
"os"
@@ -56,6 +57,24 @@ func NewApp() *cli.App {
},
},
{
+ Name: "import",
+ Usage: "Imports from a JSON dump into a database",
+ Flags: []cli.Flag{
+ &cli.StringFlag{Name: "input"},
+ },
+ Action: func(c *cli.Context) {
+ Import(c.Args().Get(0), c.String("input"))
+ },
+ },
+ {
+ Name: "export",
+ Usage: "Exports a database to JSON",
+ Action: func(c *cli.Context) {
+ path := c.Args().Get(0)
+ Export(path)
+ },
+ },
+ {
Name: "pages",
Usage: "Dumps page information for a database",
Action: func(c *cli.Context) {
@@ -144,3 +163,10 @@ func SetTestMode(value bool) {
logger = log.New(os.Stderr, "", 0)
}
}
+
+// rawMessage represents a JSON element in the import/export document.
+type rawMessage struct {
+ Type string `json:"type,omitempty"`
+ Key []byte `json:"key"`
+ Value json.RawMessage `json:"value"`
+}