-
Notifications
You must be signed in to change notification settings - Fork 92
/
main.go
101 lines (82 loc) · 2.02 KB
/
main.go
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
package main
import (
"flag"
"path/filepath"
"fmt"
"os"
"github.com/FactomProject/factomd/state"
survey "gopkg.in/AlecAivazis/survey.v1"
)
func main() {
var (
file = flag.String("f", "", "File to open")
directory = flag.String("d", "", "Directory containing multiple directories")
)
flag.Parse()
if *file != "" {
OpenSingleFile(*file)
return
}
if *directory != "" {
OpenDirectory(*directory)
}
}
func OpenSingleFile(filename string) {
wb, err := state.ReadDBStateFromDebugFile(filename)
if err != nil {
panic(err)
}
OpenBlock(wb)
}
var directories = []string{}
func OpenDirectory(directory string) {
// This will find all directories of interest
filepath.Walk(directory, FindDirectory)
fmt.Printf("Found %d directories containing DBState files\n", len(directories))
for _, s := range directories {
fmt.Println(" -", s)
}
for {
var qs = []*survey.Question{
{
Name: "option",
Prompt: &survey.Select{
Message: "Choose an option. Compare will compare all dbstates at a given height. Select will select a single dbstate file",
Options: []string{"compare", "select", "exit"},
Default: "compare",
},
},
}
// the answers will be written to this struct
answers := struct {
Option string `survey:"option"` // or you can tag fields to match a specific name
}{}
// perform the questions
err := survey.Ask(qs, &answers)
if err != nil {
fmt.Println(err.Error())
return
}
switch answers.Option {
case "exit":
return
case "compare":
CompareDirectory()
case "select":
SelectDirectory()
}
}
}
// FindDirectory will find all directories containing *.block files at it's first depth
func FindDirectory(path string, info os.FileInfo, err error) error {
// We don't care about files
if !info.IsDir() {
return nil
}
folders, err := filepath.Glob(filepath.Join(path, "*.block"))
if len(folders) != 0 {
// This directory might be useless, but it might contain a directory that has value
directories = append(directories, path)
}
return nil
}