-
Notifications
You must be signed in to change notification settings - Fork 301
/
main.go
101 lines (80 loc) · 2.12 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
package main
import (
"fmt"
"os"
"github.com/buildkite/agent/agent"
"github.com/buildkite/agent/clicommand"
"github.com/codegangsta/cli"
)
var AppHelpTemplate = `Usage:
{{.Name}} <command> [arguments...]
Available commands are:
{{range .Commands}}{{.Name}}{{with .ShortName}}, {{.}}{{end}}{{ "\t" }}{{.Usage}}
{{end}}
Use "{{.Name}} <command> --help" for more information about a command.
`
var SubcommandHelpTemplate = `Usage:
{{.Name}} {{if .Flags}}<command>{{end}} [arguments...]
Available commands are:
{{range .Commands}}{{.Name}}{{with .ShortName}}, {{.}}{{end}}{{ "\t" }}{{.Usage}}
{{end}}{{if .Flags}}
Options:
{{range .Flags}}{{.}}
{{end}}{{end}}
`
var CommandHelpTemplate = `{{.Description}}
Options:
{{range .Flags}}{{.}}
{{end}}
`
func printVersion(c *cli.Context) {
fmt.Printf("%v version %v, build %v\n", c.App.Name, c.App.Version, agent.BuildVersion())
}
func main() {
cli.AppHelpTemplate = AppHelpTemplate
cli.CommandHelpTemplate = CommandHelpTemplate
cli.SubcommandHelpTemplate = SubcommandHelpTemplate
cli.VersionPrinter = printVersion
app := cli.NewApp()
app.Name = "buildkite-agent"
app.Version = agent.Version()
app.Commands = []cli.Command{
clicommand.AgentStartCommand,
{
Name: "artifact",
Usage: "Upload/download artifacts from Buildkite jobs",
Subcommands: []cli.Command{
clicommand.ArtifactUploadCommand,
clicommand.ArtifactDownloadCommand,
clicommand.ArtifactShasumCommand,
},
},
{
Name: "meta-data",
Usage: "Get/set data from Buildkite jobs",
Subcommands: []cli.Command{
clicommand.MetaDataSetCommand,
clicommand.MetaDataGetCommand,
clicommand.MetaDataExistsCommand,
},
},
{
Name: "pipeline",
Usage: "Make changes to the pipeline of the currently running build",
Subcommands: []cli.Command{
clicommand.PipelineUploadCommand,
},
},
}
// When no sub command is used
app.Action = func(c *cli.Context) {
cli.ShowAppHelp(c)
os.Exit(1)
}
// When a sub command can't be found
app.CommandNotFound = func(c *cli.Context, command string) {
cli.ShowAppHelp(c)
os.Exit(1)
}
app.Run(os.Args)
}