-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
57 lines (46 loc) · 836 Bytes
/
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
package main
import (
"flag"
"fmt"
"log"
"os"
"github.com/mble/pgdump-metadata-extractor/extractor"
)
func run(cfg extractor.Cfg) error {
var (
fd *os.File
err error
)
switch {
case cfg.Stdin:
fd = os.Stdin
case cfg.FileName != "":
fd, err = os.Open(cfg.FileName)
if err != nil {
err = fmt.Errorf("err opening file: %w", err)
return err
}
}
defer func() {
fd.Close()
}()
json, err := extractor.Run(fd)
if err != nil {
return err
}
fmt.Printf("%s", json)
return nil
}
func main() {
cfg := extractor.Cfg{}
flag.StringVar(&cfg.FileName, "filename", "", "dump to read metadata of")
flag.BoolVar(&cfg.Stdin, "stdin", false, "configure to read from stdin")
flag.Parse()
if err := cfg.Validate(); err != nil {
log.Fatal(err)
}
err := run(cfg)
if err != nil {
log.Fatal(err)
}
}