From bb7b152af54a6338035d5715aab176f27709460c Mon Sep 17 00:00:00 2001 From: Anton Kaliaev Date: Tue, 24 Oct 2017 13:25:47 +0400 Subject: [PATCH] write docs for cutWALUntil and wal2json binaries --- scripts/cutWALUntil/main.go | 20 ++++++++++++++++---- scripts/wal2json/main.go | 11 +++++++++++ 2 files changed, 27 insertions(+), 4 deletions(-) diff --git a/scripts/cutWALUntil/main.go b/scripts/cutWALUntil/main.go index e2886fad..9dde7bf9 100644 --- a/scripts/cutWALUntil/main.go +++ b/scripts/cutWALUntil/main.go @@ -1,3 +1,10 @@ +/* + cutWALUntil is a small utility for cutting a WAL until the given height + (inclusively). Note it does not include last cs.EndHeightMessage. + + Usage: + cutWALUntil height-to-stop +*/ package main import ( @@ -10,27 +17,32 @@ import ( ) func main() { + if len(os.Args) < 4 { + fmt.Println("3 arguments required: height-to-stop ") + os.Exit(1) + } + var heightToStop uint64 var err error if heightToStop, err = strconv.ParseUint(os.Args[2], 10, 64); err != nil { - panic(fmt.Errorf("failed to parse height: %v (format: cutWALUntil in heightToStop out)", err)) + panic(fmt.Errorf("failed to parse height: %v", err)) } in, err := os.Open(os.Args[1]) if err != nil { - panic(fmt.Errorf("failed to open WAL file: %v (format: cutWALUntil in heightToStop out)", err)) + panic(fmt.Errorf("failed to open input WAL file: %v", err)) } defer in.Close() out, err := os.Create(os.Args[3]) if err != nil { - panic(fmt.Errorf("failed to open WAL file: %v (format: cutWALUntil in heightToStop out)", err)) + panic(fmt.Errorf("failed to open output WAL file: %v", err)) } defer out.Close() enc := cs.NewWALEncoder(out) - dec := cs.NewWALDecoder(in) + for { msg, err := dec.Decode() if err == io.EOF { diff --git a/scripts/wal2json/main.go b/scripts/wal2json/main.go index 46a3e17b..595660cf 100644 --- a/scripts/wal2json/main.go +++ b/scripts/wal2json/main.go @@ -1,3 +1,9 @@ +/* + wal2json converts binary WAL file to JSON. + + Usage: + wal2json +*/ package main import ( @@ -10,6 +16,11 @@ import ( ) func main() { + if len(os.Args) < 2 { + fmt.Println("missing one argument: ") + os.Exit(1) + } + f, err := os.Open(os.Args[1]) if err != nil { panic(fmt.Errorf("failed to open WAL file: %v", err))