File tree Expand file tree Collapse file tree 2 files changed +17
-0
lines changed Expand file tree Collapse file tree 2 files changed +17
-0
lines changed Original file line number Diff line number Diff 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 }
Original file line number Diff line number Diff line change 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
410go build --help
511stdout 'usage: go build'
You can’t perform that action at this time.
0 commit comments