-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
60 lines (48 loc) · 1.47 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
package main
import (
"log"
"os"
_ "github.com/go-sql-driver/mysql"
"github.com/jessevdk/go-flags"
)
type Options struct {
ConfigFile string `short:"c" long:"config" description:"Path to config file" required:"true"`
Host string `short:"h" long:"host" description:"hostname of server" default:"127.0.0.1"`
Port string `short:"P" long:"port" description:"port of server" default:"3306"`
Socket string `short:"S" long:"socket"`
User string `short:"u" long:"user" description:"user for login"`
Password string `short:"p" long:"password" description:"password for login"`
Binpath string `long:"binpath" description:"Path to mysqldump" default:"mysqldump"`
Help bool `long:"help" description:"Display this (help) message"`
Verbose []bool `short:"v" long:"verbose" description:"Show verbose debug information"`
ExtraArgs []string
}
var opts Options
func init() {
log.SetFlags(0)
}
func main() {
parser := flags.NewParser(&opts, flags.PassDoubleDash)
extraArgs, err := parser.Parse()
if opts.Help {
parser.WriteHelp(os.Stderr)
os.Exit(0)
}
if err != nil {
log.Printf("Error: %s\n\n", err.Error())
parser.WriteHelp(os.Stderr)
os.Exit(1)
}
opts.ExtraArgs = extraArgs
log.Printf("DEBUG: reading config")
config, err := NewConfig(&opts)
if err != nil {
log.Fatal(err.Error())
}
sequencer := NewDumpSequencer(config)
log.Printf("DEBUG: starting dump")
err = sequencer.Dump()
if err != nil {
log.Fatal(err.Error())
}
}