This repository was archived by the owner on Jul 2, 2022. It is now read-only.
forked from mantyr/rdb-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrdb.go
More file actions
53 lines (43 loc) · 1.17 KB
/
rdb.go
File metadata and controls
53 lines (43 loc) · 1.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package main
import (
"fmt"
"github.com/cameronpm/rdb-cli/decoder"
"github.com/cupcake/rdb"
"github.com/jessevdk/go-flags"
"log"
"os"
)
var Version = "0.2"
var formats = map[string]rdb.Decoder{
"protocol": decoder.Protocol(os.Stdout),
"diff": decoder.Diff(),
"size": decoder.Size(),
}
type rdbOptions struct {
Path string `required:"1" positional-arg-name:"RDBPATH" description:"Path to RDB file"`
}
var options struct {
Version func() `long:"version" description:"Print version and exit"`
Format string `long:"format" choice:"diff" choice:"protocol" choice:"size" description:"Output format of RDB file"`
Rdb rdbOptions `positional-args:"1"`
}
func format(rdbPath string, d rdb.Decoder) {
file, err := os.Open(rdbPath)
if err != nil {
log.Fatalf("Unable to open RDB file '%s': %s\n", options.Rdb.Path, err)
}
err = rdb.Decode(file, d)
if err != nil {
log.Fatalf("Failed to decode RDB file '%s': %s\n", options.Rdb.Path, err)
}
}
func main() {
options.Version = func() {
fmt.Printf("rdb-cli v%s\n", Version)
os.Exit(0)
}
if _, err := flags.Parse(&options); err != nil {
os.Exit(1)
}
format(options.Rdb.Path, formats[options.Format])
}