-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
82 lines (78 loc) · 1.56 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
package main
import (
"github.com/BUGLAN/zk-batch/batch"
"github.com/urfave/cli/v2"
"log"
"os"
"sort"
)
func buildApp() *cli.App {
app := &cli.App{
Name: "zk-batch",
Flags: []cli.Flag{
&cli.StringFlag{
Name: "server",
Aliases: []string{"s"},
Value: "localhost:2181",
Usage: "specify zookeeper server",
},
&cli.StringFlag{
Name: "auth",
Aliases: []string{"a"},
Usage: "zookeeper auth passport",
},
&cli.StringFlag{
Name: "digest",
Aliases: []string{"u"},
Value: "digest",
Usage: "zookeeper auth digest",
},
},
Commands: []*cli.Command{
{
Name: "import",
Aliases: []string{"i"},
Flags: []cli.Flag{
&cli.StringFlag{
Name: "filename",
Aliases: []string{"f"},
Usage: "指定导入的文件",
Required: true,
},
},
Usage: "import data to zookeeper",
Action: batch.Import,
},
{
Name: "export",
Aliases: []string{"e"},
Usage: "export data to zookeeper",
Action: batch.Export,
Flags: []cli.Flag{
&cli.StringFlag{
Name: "filename",
Aliases: []string{"f"},
Usage: "导出到指定的文件",
},
&cli.StringFlag{
Name: "path",
Aliases: []string{"p"},
Usage: "root path",
Value: "/",
},
},
},
},
}
// sort command and flags
sort.Sort(cli.FlagsByName(app.Flags))
sort.Sort(cli.CommandsByName(app.Commands))
return app
}
func main() {
app := buildApp()
err := app.Run(os.Args)
if err != nil {
log.Fatal(err)
}
}