-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
55 lines (49 loc) · 1.51 KB
/
main.go
File metadata and controls
55 lines (49 loc) · 1.51 KB
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
package main
import (
"github.com/DockerContainerService/git-syncer/pkg/client"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
prefixed "github.com/x-cray/logrus-prefixed-formatter"
)
var (
configFile, privateKeyFile string
retries, routineNum int
debug bool
version = "1.0.0"
)
var rootCmd = &cobra.Command{
Use: "git-syncer [flags]",
Version: version,
Run: func(cmd *cobra.Command, args []string) {
if debug {
logrus.SetLevel(logrus.DebugLevel)
}
c, err := client.Default(configFile, retries, routineNum, privateKeyFile)
if err != nil {
logrus.Fatalf("err1: %v", err)
}
c.Run()
},
}
func init() {
rootCmd.CompletionOptions.HiddenDefaultCmd = true
rootCmd.PersistentFlags().StringVarP(&configFile, "config", "c", "", "config file")
rootCmd.PersistentFlags().StringVar(&privateKeyFile, "privateKeyFile", "", "private key file")
rootCmd.PersistentFlags().IntVarP(&retries, "retries", "r", 3, "times to retry failed task")
rootCmd.PersistentFlags().IntVarP(&routineNum, "proc", "p", 5, "numbers of worker")
rootCmd.PersistentFlags().BoolVarP(&debug, "debug", "d", false, "enable debug mode")
}
func main() {
logger := logrus.StandardLogger()
logger.SetReportCaller(true)
logger.SetFormatter(&prefixed.TextFormatter{
DisableColors: false,
TimestampFormat: "2006-01-02 15:04:05",
FullTimestamp: true,
ForceFormatting: true,
})
logger.SetLevel(logrus.InfoLevel)
if err := rootCmd.Execute(); err != nil {
logrus.Panic(err)
}
}