forked from jfrog/jfrog-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
146 lines (130 loc) · 3.82 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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
package main
import (
"os"
"github.com/jfrog/jfrog-cli-core/utils/coreutils"
"github.com/jfrog/jfrog-cli-core/utils/log"
"github.com/jfrog/jfrog-cli/config"
"github.com/jfrog/jfrog-cli/docs/common"
"github.com/jfrog/jfrog-cli/plugins"
"github.com/jfrog/jfrog-cli/plugins/utils"
"github.com/codegangsta/cli"
"github.com/jfrog/jfrog-cli/artifactory"
"github.com/jfrog/jfrog-cli/bintray"
"github.com/jfrog/jfrog-cli/completion"
"github.com/jfrog/jfrog-cli/missioncontrol"
"github.com/jfrog/jfrog-cli/utils/cliutils"
"github.com/jfrog/jfrog-cli/xray"
clientutils "github.com/jfrog/jfrog-client-go/utils"
"github.com/jfrog/jfrog-client-go/utils/io/fileutils"
clientLog "github.com/jfrog/jfrog-client-go/utils/log"
)
const commandHelpTemplate string = `{{.HelpName}}{{if .UsageText}}
Arguments:
{{.UsageText}}
{{end}}{{if .VisibleFlags}}
Options:
{{range .VisibleFlags}}{{.}}
{{end}}{{end}}{{if .ArgsUsage}}
Environment Variables:
{{.ArgsUsage}}{{end}}
`
const appHelpTemplate string = `NAME:
{{.Name}} - {{.Usage}}
USAGE:
{{if .UsageText}}{{.UsageText}}{{else}}{{.HelpName}} {{if .VisibleFlags}}[global options]{{end}}{{if .Commands}} command [command options]{{end}} [arguments...]{{end}}
{{if .Version}}
VERSION:
{{.Version}}
{{end}}{{if len .Authors}}
AUTHOR(S):
{{range .Authors}}{{ . }}{{end}}
{{end}}{{if .Commands}}
COMMANDS:
{{range .Commands}}{{join .Names ", "}}{{ "\t" }}{{if .Description}}{{.Description}}{{else}}{{.Usage}}{{end}}
{{end}}{{end}}{{if .VisibleFlags}}
GLOBAL OPTIONS:
{{range .VisibleFlags}}{{.}}
{{end}}
Environment Variables:
` + common.GlobalEnvVars + `{{end}}
`
const subcommandHelpTemplate = `NAME:
{{.HelpName}} - {{.Description}}
USAGE:
{{if .Usage}}{{.Usage}}{{ "\n\t" }}{{end}}{{.HelpName}} command{{if .VisibleFlags}} [command options]{{end}}[arguments...]
COMMANDS:
{{range .Commands}}{{join .Names ", "}}{{ "\t" }}{{.Description}}
{{end}}{{if .VisibleFlags}}{{if .ArgsUsage}}
Arguments:
{{.ArgsUsage}}{{ "\n" }}{{end}}
OPTIONS:
{{range .VisibleFlags}}{{.}}
{{end}}
Environment Variables:
` + common.GlobalEnvVars + `{{end}}
`
func main() {
log.SetDefaultLogger()
err := execMain()
if cleanupErr := fileutils.CleanOldDirs(); cleanupErr != nil {
clientLog.Warn(cleanupErr)
}
coreutils.ExitOnErr(err)
}
func execMain() error {
// Set JFrog CLI's user-agent on the jfrog-client-go.
clientutils.SetUserAgent(coreutils.GetUserAgent())
app := cli.NewApp()
app.Name = "jfrog"
app.Usage = "See https://github.com/jfrog/jfrog-cli for usage instructions."
app.Version = cliutils.GetVersion()
args := os.Args
app.EnableBashCompletion = true
app.Commands = getCommands()
cli.CommandHelpTemplate = commandHelpTemplate
cli.AppHelpTemplate = appHelpTemplate
cli.SubcommandHelpTemplate = subcommandHelpTemplate
err := app.Run(args)
return err
}
func getCommands() []cli.Command {
cliNameSpaces := []cli.Command{
{
Name: cliutils.CmdArtifactory,
Description: "Artifactory commands",
Subcommands: artifactory.GetCommands(),
},
{
Name: cliutils.CmdBintray,
Description: "Bintray commands",
Subcommands: bintray.GetCommands(),
},
{
Name: cliutils.CmdMissionControl,
Description: "Mission Control commands",
Subcommands: missioncontrol.GetCommands(),
},
{
Name: cliutils.CmdXray,
Description: "Xray commands",
Subcommands: xray.GetCommands(),
},
{
Name: cliutils.CmdCompletion,
Description: "Generate autocomplete scripts",
Subcommands: completion.GetCommands(),
},
{
Name: cliutils.CmdPlugin,
Description: "Plugins commands",
Subcommands: plugins.GetCommands(),
},
{
Name: cliutils.CmdConfig,
Aliases: []string{"c"},
Description: "Config commands",
Subcommands: config.GetCommands(),
},
}
return append(cliNameSpaces, utils.GetPlugins()...)
}