-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
75 lines (60 loc) · 1.83 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
package main
import (
"flag"
"fmt"
"os"
)
// goreleaser updates these at build time. These are the defaults used
// for a native Go build with no ldflags overrides.
var (
version = "dev"
commit = "unknown"
)
// errPrint prints a formatted message to stderr and exits non-zero.
func errPrint(msg string, args ...interface{}) {
fmt.Fprintf(os.Stderr, "ERROR: "+msg, args...)
os.Exit(1)
}
// infoPrint prints a formatted message to stderr but does not exit.
func infoPrint(msg string, args ...interface{}) {
fmt.Fprintf(os.Stderr, "INFO: "+msg, args...)
}
func main() {
dbFile := flag.String("db", "OBJ_DUMP.sqlite", "SQLite Database file path to populate")
forceFlag := flag.Bool("force", false, "Add OBJ_DUMP data to an existing database")
versionFlag := flag.Bool("version", false, "Print the version and quit")
flag.Parse()
if *versionFlag {
infoPrint("dumpdb version %s - commit %s\n", version, commit)
os.Exit(0)
}
if _, err := os.Stat(*dbFile); err == nil && !(*forceFlag) {
errPrint(
"db %q exists and -force was not specified. Remove the database or add -force\n",
*dbFile)
}
// Open the database.
db, err := openDB(*dbFile)
if err != nil {
errPrint("opening db: %v\n", err)
}
infoPrint("Using database file %q\n", *dbFile)
defer func() { _ = db.Close() }()
// Open the OBJ_DUMP file.
rest := flag.Args()
if len(rest) != 1 {
errPrint("usage %s [flags] <OBJ_DUMP file path>\n", os.Args[0])
}
objDumpFileName := rest[0]
infoPrint("Reading OBJ_DUMP from %q\n", objDumpFileName)
objDumpFile, err := os.Open(objDumpFileName)
if err != nil {
errPrint("%v\n", err)
}
// Backfill the DB by parsing the OBJ_DUMP file.
count, err := backfill(objDumpFile, db)
if err != nil {
errPrint("backfilling db: %v\n", err)
}
infoPrint("Loaded %d objects from %q into DB %q\n", count, objDumpFileName, *dbFile)
}