forked from flanksource/canary-checker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
68 lines (57 loc) · 1.42 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
package main
import (
"fmt"
"os"
"github.com/flanksource/canary-checker/cmd"
"github.com/flanksource/commons/logger"
"github.com/spf13/cobra"
"github.com/spf13/cobra/doc"
)
var (
version = "dev"
commit = "none"
date = "unknown"
)
func main() {
var root = &cobra.Command{
Use: "canary-checker",
PersistentPreRun: func(cmd *cobra.Command, args []string) {
logger.UseZap(cmd.Flags())
logger.Infof("Starting %s", version)
},
}
logger.BindFlags(root.PersistentFlags())
root.AddCommand(cmd.Run, cmd.Serve, cmd.Operator)
if len(commit) > 8 {
version = fmt.Sprintf("%v, commit %v, built at %v", version, commit[0:8], date)
}
root.AddCommand(&cobra.Command{
Use: "version",
Short: "Print the version of canary-checker",
Args: cobra.MinimumNArgs(0),
Run: func(cmd *cobra.Command, args []string) {
fmt.Println(version)
},
})
docs := &cobra.Command{
Use: "docs",
Short: "generate documentation",
}
docs.AddCommand(&cobra.Command{
Use: "cli [PATH]",
Short: "generate CLI documentation",
Args: cobra.MinimumNArgs(1),
Run: func(cmd *cobra.Command, args []string) {
err := doc.GenMarkdownTree(root, args[0])
if err != nil {
logger.Fatalf("error creating docs", err)
}
},
})
docs.AddCommand(cmd.APIDocs)
root.AddCommand(docs)
root.SetUsageTemplate(root.UsageTemplate() + fmt.Sprintf("\nversion: %s\n ", version))
if err := root.Execute(); err != nil {
os.Exit(1)
}
}