-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
52 lines (45 loc) · 1.57 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
package main
import (
"fmt"
"runtime/debug"
"github.com/jskcnsl/eesc/config"
"github.com/spf13/cobra"
)
func main() {
rootCmd := &cobra.Command{
Use: "eesc",
Short: "Easy Elasticsearch Client",
}
rootCmd.PersistentFlags().StringVarP(&config.ServerAddress, "server", "s", "", "Address of database server")
rootCmd.PersistentFlags().StringVarP(&config.IndexName, "idx", "x", "", "Index to work around")
rootCmd.PersistentFlags().BoolVarP(&config.Verbose, "verbose", "v", false, "show details")
rootCmd.PersistentFlags().StringVarP(&config.QueryExp, "query", "q", "", "single query expression")
rootCmd.PersistentFlags().StringVarP(&config.JoinExp, "join", "j", "", "query which will join to each expression")
rootCmd.PersistentFlags().StringVarP(&config.ExpFile, "file", "f", "", "collection of exporession")
rootCmd.PersistentFlags().StringVarP(&config.OutputFile, "output", "o", "", "output file")
_ = rootCmd.MarkFlagRequired("server")
_ = rootCmd.MarkFlagRequired("idx")
searchCmd := &cobra.Command{
Use: "search",
Short: "search elasticsearch with query",
RunE: search,
PreRunE: initOutput,
PostRun: closeOutput,
}
searchCmd.Flags().IntVarP(&config.Size, "size", "l", 10, "size of result")
searchCmd.Flags().IntVarP(&config.Offset, "offset", "A", 0, "search offset")
rootCmd.AddCommand(
searchCmd,
&cobra.Command{
Use: "count",
Short: "get count result with query",
RunE: count,
PreRunE: initOutput,
PostRun: closeOutput,
},
)
if err := rootCmd.Execute(); err != nil {
fmt.Println(string(debug.Stack()))
panic(err)
}
}