github.com/jfrog/jfrog-cli-go@v1.22.1-0.20200318093948-4826ef344ffd/main.go (about) 1 package main 2 3 import ( 4 "github.com/codegangsta/cli" 5 "github.com/jfrog/jfrog-cli-go/artifactory" 6 "github.com/jfrog/jfrog-cli-go/bintray" 7 "github.com/jfrog/jfrog-cli-go/completion" 8 "github.com/jfrog/jfrog-cli-go/docs/common" 9 "github.com/jfrog/jfrog-cli-go/missioncontrol" 10 "github.com/jfrog/jfrog-cli-go/utils/cliutils" 11 "github.com/jfrog/jfrog-cli-go/utils/log" 12 "github.com/jfrog/jfrog-cli-go/xray" 13 "github.com/jfrog/jfrog-client-go/utils" 14 "os" 15 ) 16 17 const commandHelpTemplate string = `{{.HelpName}}{{if .UsageText}} 18 Arguments: 19 {{.UsageText}} 20 {{end}}{{if .VisibleFlags}} 21 Options: 22 {{range .VisibleFlags}}{{.}} 23 {{end}}{{end}}{{if .ArgsUsage}} 24 Environment Variables: 25 {{.ArgsUsage}}{{end}} 26 27 ` 28 29 const appHelpTemplate string = `NAME: 30 {{.Name}} - {{.Usage}} 31 32 USAGE: 33 {{if .UsageText}}{{.UsageText}}{{else}}{{.HelpName}} {{if .VisibleFlags}}[global options]{{end}}{{if .Commands}} command [command options]{{end}} [arguments...]{{end}} 34 {{if .Version}} 35 VERSION: 36 {{.Version}} 37 {{end}}{{if len .Authors}} 38 AUTHOR(S): 39 {{range .Authors}}{{ . }}{{end}} 40 {{end}}{{if .Commands}} 41 COMMANDS: 42 {{range .Commands}}{{join .Names ", "}}{{ "\t" }}{{.Usage}} 43 {{end}}{{end}}{{if .VisibleFlags}} 44 GLOBAL OPTIONS: 45 {{range .VisibleFlags}}{{.}} 46 {{end}} 47 Environment Variables: 48 ` + common.GlobalEnvVars + `{{end}} 49 50 ` 51 52 const subcommandHelpTemplate = `NAME: 53 {{.HelpName}} - {{.Usage}} 54 55 USAGE: 56 {{.HelpName}} command{{if .VisibleFlags}} [command options]{{end}}[arguments...] 57 58 COMMANDS: 59 {{range .Commands}}{{join .Names ", "}}{{ "\t" }}{{.Usage}} 60 {{end}}{{if .VisibleFlags}} 61 OPTIONS: 62 {{range .VisibleFlags}}{{.}} 63 {{end}} 64 Environment Variables: 65 ` + common.GlobalEnvVars + `{{end}} 66 67 ` 68 69 func main() { 70 log.SetDefaultLogger() 71 err := execMain() 72 cliutils.ExitOnErr(err) 73 } 74 75 func execMain() error { 76 // Set JFrog CLI's user-agent on the jfrog-client-go. 77 utils.SetUserAgent(cliutils.GetUserAgent()) 78 79 app := cli.NewApp() 80 app.Name = "jfrog" 81 app.Usage = "See https://github.com/jfrog/jfrog-cli-go for usage instructions." 82 app.Version = cliutils.GetVersion() 83 args := os.Args 84 app.EnableBashCompletion = true 85 app.Commands = getCommands() 86 cli.CommandHelpTemplate = commandHelpTemplate 87 cli.AppHelpTemplate = appHelpTemplate 88 cli.SubcommandHelpTemplate = subcommandHelpTemplate 89 err := app.Run(args) 90 return err 91 } 92 93 func getCommands() []cli.Command { 94 return []cli.Command{ 95 { 96 Name: cliutils.CmdArtifactory, 97 Usage: "Artifactory commands", 98 Subcommands: artifactory.GetCommands(), 99 }, 100 { 101 Name: cliutils.CmdBintray, 102 Usage: "Bintray commands", 103 Subcommands: bintray.GetCommands(), 104 }, 105 { 106 Name: cliutils.CmdMissionControl, 107 Usage: "Mission Control commands", 108 Subcommands: missioncontrol.GetCommands(), 109 }, 110 { 111 Name: cliutils.CmdXray, 112 Usage: "Xray commands", 113 Subcommands: xray.GetCommands(), 114 }, 115 { 116 Name: cliutils.CmdCompletion, 117 Usage: "Generate autocomplete scripts", 118 Subcommands: completion.GetCommands(), 119 }, 120 } 121 }