From 29674d87e697e10b658d5676a2f547d555c2c534 Mon Sep 17 00:00:00 2001 From: Zeke Lu Date: Tue, 25 Oct 2022 23:18:45 +0000 Subject: [PATCH] flag: clarify that the main func at pkg.go.dev is part of a testing suite flag.Example() has this comment: ... one must execute, typically at the start of main (not init!): flag.Parse() We don't run it here because this is not a main function This example function will be renamed to "main" at pkg.go.dev, which makes the comment confusing. See https://pkg.go.dev/flag#example-package. This change modify the comment to clarify this situation. Change-Id: I17357fdaaefe54791fff8fbbf6a33003af207f88 GitHub-Last-Rev: eeea8ce39cda3321d51c6cfe29fbcb2444fbf9cd GitHub-Pull-Request: golang/go#56411 Reviewed-on: https://go-review.googlesource.com/c/go/+/445315 Run-TryBot: Ian Lance Taylor Run-TryBot: Rob Pike Reviewed-by: Ian Lance Taylor Reviewed-by: Rob Pike Auto-Submit: Ian Lance Taylor Reviewed-by: Heschi Kreinick TryBot-Result: Gopher Robot --- src/flag/example_test.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/flag/example_test.go b/src/flag/example_test.go index 04a0d20ee4..088447d43f 100644 --- a/src/flag/example_test.go +++ b/src/flag/example_test.go @@ -78,6 +78,8 @@ func Example() { // to enable the flag package to see the flags defined there, one must // execute, typically at the start of main (not init!): // flag.Parse() - // We don't run it here because this is not a main function and - // the testing suite has already parsed the flags. + // We don't call it here because this code is a function called "Example" + // that is part of the testing suite for the package, which has already + // parsed the flags. When viewed at pkg.go.dev, however, the function is + // renamed to "main" and it could be run as a standalone example. } -- 2.48.1