-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
121 lines (99 loc) · 2.91 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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
package main
import (
"fmt"
"os"
"sort"
"strings"
"github.com/urfave/cli/v2"
"go.uber.org/zap"
"rmk/commands"
"rmk/logger"
)
var (
builtBy string
commit string
date string
name string
target string
timestamp string
version string
)
// Override default help template parsing with add [GLOBAL OPTIONS] for all commands and subcommands
func init() {
var output string
for _, val := range commands.FlagsGlobal() {
output += fmt.Sprintf(" %s\n", val.String())
}
cli.CommandHelpTemplate += `
GLOBAL OPTIONS:
` + output + `{{range $index, $option := .VisibleFlags}}{{if eq $option.Name "help"}}{{" "}}{{$option}}{{end}}{{end}}
`
cli.SubcommandHelpTemplate += `
GLOBAL OPTIONS:
` + output + `{{range $index, $option := .VisibleFlags}}{{if eq $option.Name "help"}}{{" "}}{{$option}}{{end}}{{end}}
`
cli.MarkdownDocTemplate = `{{if gt .SectionNum 0}}% {{ .App.Name }} {{ .SectionNum }}
{{end}}# NAME
` + strings.ToUpper(name) + ` CLI{{ if .App.Usage }} - {{ .App.Usage }}{{ end }}
## SYNOPSIS
{{ .App.Name }}
{{ if .SynopsisArgs }}
` + "```" + `
{{ range $v := .SynopsisArgs }}{{ $v }}{{ end }}` + "```" + `
{{ end }}{{ if .App.Description }}
## DESCRIPTION
Command line tool for reduced management of the provision of Kubernetes clusters in different environments and management of service releases.
**BuiltBy:** ` + builtBy + ` <br />
**Commit:** ` + commit + ` <br />
**Date:** ` + date + ` <br />
**Target:** ` + target + `
{{ end }}
**Usage**:
` + "```" + `{{ if .App.UsageText }}
{{ .App.UsageText }}
{{ else }}
{{ .App.Name }} [GLOBAL OPTIONS] command [COMMAND OPTIONS] [ARGUMENTS...]
{{ end }}` + "```" + `
{{ if .GlobalArgs }}
## GLOBAL OPTIONS
{{ range $v := .GlobalArgs }}
{{ $v }}{{ end }}
{{ end }}{{ if .Commands }}
## COMMANDS
{{ range $v := .Commands }}
#{{ $v }}{{ end }}{{ end }}`
}
func runCLI() *cli.App {
app := cli.NewApp()
app.Name = name
app.Description = "Command line tool for reduced management of the " +
"provision of Kubernetes clusters in different environments and management of service releases." +
fmt.Sprintf("\nBuiltBy: %s\nCommit: %s\nDate: %s\nTarget: %s",
builtBy, commit, date, target)
app.Usage = "Reduced management for Kubernetes"
app.Version = version
app.Metadata = map[string]interface{}{
"binaryName": name + "_" + target,
"timestamp": timestamp,
"version": version,
}
app.Flags = commands.FlagsGlobal()
app.Before = func(c *cli.Context) error {
logger.Init(c.String("log-format"), c.String("log-level"))
return nil
}
// Enable command auto-completion (the --generate-bash-completion flag is provided out of box)
// Incompatible with UseShortOptionHandling option
app.EnableBashCompletion = true
// Enable flag and command suggestions
app.Suggest = true
app.Commands = commands.Commands()
sort.Sort(cli.CommandsByName(app.Commands))
return app
}
func main() {
err := runCLI().Run(os.Args)
if err != nil {
zap.S().Fatal(err)
}
}