forked from buildkite/agent
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
119 lines (97 loc) · 2.59 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
package main
// see https://blog.golang.org/generate
//go:generate go run mime/generate.go
//go:generate go fmt mime/mime.go
import (
"fmt"
"os"
"github.com/buildkite/agent/v3/agent"
"github.com/buildkite/agent/v3/clicommand"
"github.com/urfave/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 .VisibleFlags}}<command>{{end}} [arguments...]
Available commands are:
{{range .Commands}}{{.Name}}{{with .ShortName}}, {{.}}{{end}}{{ "\t" }}{{.Usage}}
{{end}}{{if .VisibleFlags}}
Options:
{{range .VisibleFlags}}{{.}}
{{end}}{{end}}
`
var CommandHelpTemplate = `{{.Description}}
Options:
{{range .VisibleFlags}}{{.}}
{{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,
clicommand.AnnotateCommand,
{
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,
clicommand.MetaDataKeysCommand,
},
},
{
Name: "pipeline",
Usage: "Make changes to the pipeline of the currently running build",
Subcommands: []cli.Command{
clicommand.PipelineUploadCommand,
},
},
{
Name: "step",
Usage: "Get or update an attribute of a build step",
Subcommands: []cli.Command{
clicommand.StepGetCommand,
clicommand.StepUpdateCommand,
},
},
clicommand.BootstrapCommand,
}
// 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)
}
if err := app.Run(os.Args); err != nil {
fmt.Printf("%v\n", err)
os.Exit(1)
}
}