Skip to content

Commit 0226439

Browse files
authored
Merge pull request #3334 from buildkite/better-helptext
Better helptext
2 parents f900bf9 + 454ed5f commit 0226439

File tree

9 files changed

+57
-42
lines changed

9 files changed

+57
-42
lines changed

clicommand/agent_pause.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ type AgentPauseConfig struct {
3939

4040
var AgentPauseCommand = cli.Command{
4141
Name: "pause",
42+
Category: categoryJobCommands,
4243
Usage: "Pause the agent",
4344
Description: pauseDescription,
4445
Flags: slices.Concat(globalFlags(), apiFlags(), []cli.Flag{

clicommand/agent_resume.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ type AgentResumeConfig struct {
3232

3333
var AgentResumeCommand = cli.Command{
3434
Name: "resume",
35+
Category: categoryJobCommands,
3536
Usage: "Resume the agent",
3637
Description: resumeDescription,
3738
Flags: slices.Concat(globalFlags(), apiFlags()),

clicommand/agent_stop.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ type AgentStopConfig struct {
3838

3939
var AgentStopCommand = cli.Command{
4040
Name: "stop",
41+
Category: categoryJobCommands,
4142
Usage: "Stop the agent",
4243
Description: stopDescription,
4344
Flags: slices.Concat(globalFlags(), apiFlags(), []cli.Flag{

clicommand/annotate.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,8 @@ type AnnotateConfig struct {
7070

7171
var AnnotateCommand = cli.Command{
7272
Name: "annotate",
73-
Usage: "Annotate the build page within the Buildkite UI with text from within a Buildkite job",
73+
Category: categoryJobCommands,
74+
Usage: "Annotate the build page in the Buildkite UI with information from within a Buildkite job",
7475
Description: annotateHelpDescription,
7576
Flags: slices.Concat(globalFlags(), apiFlags(), []cli.Flag{
7677
cli.StringFlag{

clicommand/bootstrap.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,8 @@ type BootstrapConfig struct {
106106

107107
var BootstrapCommand = cli.Command{
108108
Name: "bootstrap",
109-
Usage: "Run a Buildkite job locally",
109+
Usage: "Harness used internally by the agent to run jobs as subprocesses",
110+
Category: categoryInternal,
110111
Description: bootstrapHelpDescription,
111112
Flags: []cli.Flag{
112113
cli.StringFlag{

clicommand/commands.go

Lines changed: 40 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,32 @@ package clicommand
22

33
import "github.com/urfave/cli"
44

5+
const (
6+
categoryJobCommands = "Commands that can be run within a Buildkite job"
7+
categoryInternal = "Internal commands, not intended to be run by users"
8+
)
9+
510
var BuildkiteAgentCommands = []cli.Command{
611
// These commands are special. The have a different lifecycle to the others
712
AgentStartCommand,
813
BootstrapCommand,
14+
KubernetesBootstrapCommand,
915

1016
// These are in alphabetical order
1117
AcknowledgementsCommand,
1218
AnnotateCommand,
1319
{
14-
Name: "annotation",
15-
Usage: "Make changes to an annotation on the currently running build",
20+
Name: "annotation",
21+
Category: categoryJobCommands,
22+
Usage: "Make changes to annotations on the currently running build",
1623
Subcommands: []cli.Command{
1724
AnnotationRemoveCommand,
1825
},
1926
},
2027
{
21-
Name: "artifact",
22-
Usage: "Upload/download artifacts from Buildkite jobs",
28+
Name: "artifact",
29+
Category: categoryJobCommands,
30+
Usage: "Upload/download artifacts from Buildkite jobs",
2331
Subcommands: []cli.Command{
2432
ArtifactUploadCommand,
2533
ArtifactDownloadCommand,
@@ -28,15 +36,17 @@ var BuildkiteAgentCommands = []cli.Command{
2836
},
2937
},
3038
{
31-
Name: "build",
32-
Usage: "Interact with a Buildkite build",
39+
Name: "build",
40+
Category: categoryJobCommands,
41+
Usage: "Interact with a Buildkite build",
3342
Subcommands: []cli.Command{
3443
BuildCancelCommand,
3544
},
3645
},
3746
{
38-
Name: "env",
39-
Usage: "Process environment subcommands",
47+
Name: "env",
48+
Category: categoryJobCommands,
49+
Usage: "Interact with the environment of the currently running build",
4050
Subcommands: []cli.Command{
4151
EnvDumpCommand,
4252
EnvGetCommand,
@@ -45,10 +55,10 @@ var BuildkiteAgentCommands = []cli.Command{
4555
},
4656
},
4757
GitCredentialsHelperCommand,
48-
KubernetesBootstrapCommand,
4958
{
50-
Name: "lock",
51-
Usage: "Process lock subcommands",
59+
Name: "lock",
60+
Category: categoryJobCommands,
61+
Usage: "Lock or unlock resources for the currently running build",
5262
Subcommands: []cli.Command{
5363
LockAcquireCommand,
5464
LockDoCommand,
@@ -58,15 +68,17 @@ var BuildkiteAgentCommands = []cli.Command{
5868
},
5969
},
6070
{
61-
Name: "redactor",
62-
Usage: "Redact sensitive information from logs",
71+
Name: "redactor",
72+
Category: categoryJobCommands,
73+
Usage: "Redact sensitive information from logs",
6374
Subcommands: []cli.Command{
6475
RedactorAddCommand,
6576
},
6677
},
6778
{
68-
Name: "meta-data",
69-
Usage: "Get/set data from Buildkite jobs",
79+
Name: "meta-data",
80+
Category: categoryJobCommands,
81+
Usage: "Get/set metadata from Buildkite jobs",
7082
Subcommands: []cli.Command{
7183
MetaDataSetCommand,
7284
MetaDataGetCommand,
@@ -75,31 +87,35 @@ var BuildkiteAgentCommands = []cli.Command{
7587
},
7688
},
7789
{
78-
Name: "oidc",
79-
Usage: "Interact with Buildkite OpenID Connect (OIDC)",
90+
Name: "oidc",
91+
Category: categoryJobCommands,
92+
Usage: "Interact with Buildkite OpenID Connect (OIDC)",
8093
Subcommands: []cli.Command{
8194
OIDCRequestTokenCommand,
8295
},
8396
},
8497
AgentPauseCommand,
8598
{
86-
Name: "pipeline",
87-
Usage: "Make changes to the pipeline of the currently running build",
99+
Name: "pipeline",
100+
Category: categoryJobCommands,
101+
Usage: "Make changes to the pipeline of the currently running build",
88102
Subcommands: []cli.Command{
89103
PipelineUploadCommand,
90104
},
91105
},
92106
AgentResumeCommand,
93107
{
94-
Name: "secret",
95-
Usage: "Interact with Pipelines Secrets",
108+
Name: "secret",
109+
Category: categoryJobCommands,
110+
Usage: "Interact with Pipelines Secrets",
96111
Subcommands: []cli.Command{
97112
SecretGetCommand,
98113
},
99114
},
100115
{
101-
Name: "step",
102-
Usage: "Get or update an attribute of a build step, or cancel unfinished jobs for a step",
116+
Name: "step",
117+
Category: categoryJobCommands,
118+
Usage: "Get or update an attribute of a build step, or cancel unfinished jobs for a step",
103119
Subcommands: []cli.Command{
104120
StepGetCommand,
105121
StepUpdateCommand,
@@ -109,7 +125,7 @@ var BuildkiteAgentCommands = []cli.Command{
109125
AgentStopCommand,
110126
{
111127
Name: "tool",
112-
Usage: "Utility commands, intended for users and operators of the agent to run directly on their machines, and not as part of a Buildkite job",
128+
Usage: "Utilities for working with the Buildkite Agent",
113129
Subcommands: []cli.Command{
114130
ToolKeygenCommand,
115131
ToolSignCommand,

clicommand/git_credentials_helper.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@ const gitCredentialsHelperHelpDescription = `Usage:
2020
2121
Description:
2222
23-
[EXPERIMENTAL]
24-
2523
Ask buildkite for credentials to use to authenticate with Github when cloning via HTTPS.
2624
The credentials are returned in the git-credential format.
2725
@@ -45,7 +43,8 @@ type GitCredentialsHelperConfig struct {
4543

4644
var GitCredentialsHelperCommand = cli.Command{
4745
Name: "git-credentials-helper",
48-
Usage: "Ask buildkite for credentials to use to authenticate with Github when cloning",
46+
Usage: "Internal process used by hosted compute jobs to authenticate with Github",
47+
Category: categoryInternal,
4948
Description: gitCredentialsHelperHelpDescription,
5049
Flags: append(globalFlags(),
5150
cli.StringFlag{

clicommand/kubernetes_bootstrap.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ type KubernetesBootstrapConfig struct {
3939

4040
var KubernetesBootstrapCommand = cli.Command{
4141
Name: "kubernetes-bootstrap",
42-
Usage: "Rebootstraps the command after connecting to the Kubernetes socket",
42+
Usage: "Harness used internally by the agent to run jobs on Kubernetes",
43+
Category: categoryInternal,
4344
Description: bootstrapHelpDescription,
4445
Flags: []cli.Flag{
4546
KubernetesContainerIDFlag,

main.go

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,12 @@ import (
1616
)
1717

1818
const appHelpTemplate = `Usage:
19-
2019
{{.Name}} <command> [options...]
2120
22-
Available commands are:
23-
24-
{{range .Commands}}{{.Name}}{{with .ShortName}}, {{.}}{{end}}{{ "\t" }}{{.Usage}}
25-
{{end}}
21+
Available commands are: {{range .VisibleCategories}}{{if .Name}}
22+
{{.Name}}:{{range .VisibleCommands}}
23+
{{join .Names ", "}}{{"\t"}}{{.Usage}}{{end}}{{"\n"}}{{else}}{{range .VisibleCommands}}
24+
{{join .Names ", "}}{{"\t"}}{{.Usage}}{{end}}{{"\n"}}{{end}}{{end}}
2625
Use "{{.Name}} <command> --help" for more information about a command.
2726
`
2827

@@ -65,15 +64,10 @@ func main() {
6564
app.Commands = clicommand.BuildkiteAgentCommands
6665
app.ErrWriter = os.Stderr
6766

68-
// When no sub command is used
69-
app.Action = func(c *cli.Context) {
70-
_ = cli.ShowAppHelp(c)
71-
os.Exit(1)
72-
}
73-
7467
// When a sub command can't be found
7568
app.CommandNotFound = func(c *cli.Context, command string) {
76-
_ = cli.ShowAppHelp(c)
69+
fmt.Fprintf(app.ErrWriter, "buildkite-agent: unknown subcommand %q\n", command)
70+
fmt.Fprintf(app.ErrWriter, "Run '%s --help' for usage.\n", c.App.Name)
7771
os.Exit(1)
7872
}
7973

0 commit comments

Comments
 (0)