Skip to content

Commit

Permalink
File Location Flag (#2709)
Browse files Browse the repository at this point in the history
FAB-18425

Signed-off-by: Julian Castrence <juliancastrence@ibm.com>

Co-authored-by: Julian Castrence <juliancastrence@ibm.com>
  • Loading branch information
jcastrence and jrc-ibm authored Jun 30, 2021
1 parent b5e0d27 commit 4c4e58c
Showing 1 changed file with 21 additions and 5 deletions.
26 changes: 21 additions & 5 deletions cmd/ledger/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,23 @@ package main
import (
"fmt"
"os"
"path/filepath"

"github.com/hyperledger/fabric/internal/ledger"
"gopkg.in/alecthomas/kingpin.v2"
)

const (
resultFilename = "./result.json"
resultFilename = "result.json"
)

var (
app = kingpin.New("ledger", "Ledger Utility Tool")

compare = app.Command("compare", "Compare two ledgers via their snapshots.")
snapshotPath1 = compare.Arg("snapshotPath1", "File path to first ledger snapshot.").Required().String()
snapshotPath2 = compare.Arg("snapshotPath2", "File path to second ledger snapshot.").Required().String()
snapshotPath1 = compare.Arg("snapshotPath1", "First ledger snapshot directory.").Required().String()
snapshotPath2 = compare.Arg("snapshotPath2", "Second ledger snapshot directory.").Required().String()
outputDir = compare.Flag("outputDir", "Snapshot comparison json results output directory. Default is the current directory.").Short('o').String()

troubleshoot = app.Command("troubleshoot", "Identify potentially divergent transactions.")

Expand All @@ -39,16 +41,30 @@ func main() {
return
}

// Determine result json file location
var resultFilepath string
if outputDir != nil {
resultFilepath = *outputDir
} else {
resultFilepath, err = os.Getwd()
if err != nil {
fmt.Println(err)
return
}
}
resultFilepath = filepath.Join(resultFilepath, resultFilename)

// Command logic
switch command {

case compare.FullCommand():

count, err := ledger.Compare(*snapshotPath1, *snapshotPath2, resultFilename)
count, err := ledger.Compare(*snapshotPath1, *snapshotPath2, resultFilepath)
if err != nil {
fmt.Println(err)
return
}
fmt.Printf("\nSuccessfully compared snapshots. Result saved to %s. Total differences found: %v\n", resultFilename, count)
fmt.Printf("\nSuccessfully compared snapshots. Result saved to %s. Total differences found: %d\n", resultFilepath, count)

case troubleshoot.FullCommand():

Expand Down

0 comments on commit 4c4e58c

Please sign in to comment.