Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

File Location Flag #2709

Merged
merged 1 commit into from
Jun 30, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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