Skip to content

Commit 70b640f

Browse files
committed
support go --help
1 parent e89f7ca commit 70b640f

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

src/cmd/go/main.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,12 +109,23 @@ 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
113+
var globalHelp bool
114+
flag.BoolVar(&globalHelp, "help", false, "show help")
115+
112116
flag.Usage = base.Usage
113117
flag.Parse()
114118
counter.Inc("go/invocations")
115119
counter.CountFlags("go/flag:", *flag.CommandLine)
116120

117121
args := flag.Args()
122+
123+
// Handle global --help flag
124+
if globalHelp {
125+
help.Help(os.Stdout, nil)
126+
return
127+
}
128+
118129
if len(args) < 1 {
119130
base.Usage()
120131
}

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

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

3+
# go --help shows main help (not an error)
4+
go --help
5+
stdout 'Go is a tool for managing Go source code'
6+
stdout 'Usage:'
7+
stdout 'go <command> \[arguments\]'
8+
39
# go build --help shows full help
410
go build --help
511
stdout 'usage: go build'

0 commit comments

Comments
 (0)