Skip to content

Commit 37c78b5

Browse files
committed
Update help flag from --help to -help across commands and tests
1 parent 70b640f commit 37c78b5

File tree

2 files changed

+22
-23
lines changed

2 files changed

+22
-23
lines changed

src/cmd/go/main.go

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -109,23 +109,22 @@ func main() {
109109
if !cmdIsGoTelemetryOff {
110110
telemetry.MaybeParent() // Run the upload process. Opening the counter file is idempotent.
111111
}
112-
// Add global --help flag support
112+
// Add global -help flag support
113113
var globalHelp bool
114114
flag.BoolVar(&globalHelp, "help", false, "show help")
115-
116115
flag.Usage = base.Usage
117116
flag.Parse()
118117
counter.Inc("go/invocations")
119118
counter.CountFlags("go/flag:", *flag.CommandLine)
120119

121120
args := flag.Args()
122-
123-
// Handle global --help flag
121+
122+
// Handle global -help flag
124123
if globalHelp {
125124
help.Help(os.Stdout, nil)
126125
return
127126
}
128-
127+
129128
if len(args) < 1 {
130129
base.Usage()
131130
}
@@ -321,7 +320,7 @@ func invoke(cmd *base.Command, args []string) {
321320
}
322321
}
323322

324-
// Add --help flag support to all commands
323+
// Add -help flag support to all commands
325324
var helpFlag bool
326325
if !cmd.CustomFlags {
327326
cmd.Flag.BoolVar(&helpFlag, "help", false, "show help")
@@ -342,7 +341,7 @@ func invoke(cmd *base.Command, args []string) {
342341
base.SetFromGOFLAGS(&cmd.Flag)
343342
cmd.Flag.Parse(args[1:])
344343

345-
// Check if --help flag was set and show full help
344+
// Check if -help flag was set and show full help
346345
if helpFlag {
347346
help.Help(os.Stdout, strings.Fields(cmd.LongName()))
348347
base.Exit()

src/cmd/go/testdata/script/help_flag.txt

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,45 @@
1-
# Test that --help flag works for go commands
1+
# Test that -help flag works for go commands
22

3-
# go --help shows main help (not an error)
4-
go --help
3+
# go -help shows main help (not an error)
4+
go -help
55
stdout 'Go is a tool for managing Go source code'
66
stdout 'Usage:'
77
stdout 'go <command> \[arguments\]'
88

9-
# go build --help shows full help
10-
go build --help
9+
# go build -help shows full help
10+
go build -help
1111
stdout 'usage: go build'
1212
stdout 'Build compiles the packages'
1313
stdout 'For more about specifying packages'
1414

15-
# go install --help shows full help
16-
go install --help
15+
# go install -help shows full help
16+
go install -help
1717
stdout 'usage: go install'
1818
stdout 'Install compiles and installs'
1919
stdout 'For more about specifying packages'
2020

21-
# go get --help shows full help
22-
go get --help
21+
# go get -help shows full help
22+
go get -help
2323
stdout 'usage: go get'
2424
stdout 'Get resolves its command-line arguments'
2525
stdout 'See also: go build, go install'
2626

27-
# go fmt --help shows full help
28-
go fmt --help
27+
# go fmt -help shows full help
28+
go fmt -help
2929
stdout 'usage: go fmt'
3030
stdout 'Fmt runs the command'
3131
stdout 'See also: go fix, go vet'
3232

33-
# go run --help shows full help
34-
go run --help
33+
# go run -help shows full help
34+
go run -help
3535
stdout 'usage: go run'
3636
stdout 'Run compiles and runs'
3737
stdout 'See also: go build'
3838

39-
# go run program.go --help should pass --help to the program, not show go run help
40-
go run helpprog.go --help
39+
# go run program.go -help should pass -help to the program, not show go run help
40+
go run helpprog.go -help
4141
stdout 'Program help message'
42-
stdout 'Arguments: \[.*helpprog.*--help\]'
42+
stdout 'Arguments: \[.*helpprog.*-help\]'
4343

4444
-- helpprog.go --
4545
package main

0 commit comments

Comments
 (0)