aboutsummaryrefslogtreecommitdiff
path: root/src/flag
AgeCommit message (Collapse)Author
2024-05-07flag: replace sort.Slice with slices.SortFuncaimuz
Change-Id: I874f0c0399cb09de4fe4dd2097602c5fa0512b12 GitHub-Last-Rev: 73be01ae2a27adf0b7629a198057674018b5d392 GitHub-Pull-Request: golang/go#67223 Reviewed-on: https://go-review.googlesource.com/c/go/+/583735 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Ian Lance Taylor <iant@google.com> Auto-Submit: Ian Lance Taylor <iant@google.com> Reviewed-by: Cherry Mui <cherryyz@google.com>
2023-10-18flag: add available godoc linkcui fliter
Change-Id: I00d49ded65801ab12322f711d1ac6131d69aea34 Reviewed-on: https://go-review.googlesource.com/c/go/+/535081 Reviewed-by: Carlos Amedee <carlos@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: shuang cui <imcusg@gmail.com> Reviewed-by: Ian Lance Taylor <iant@google.com> Auto-Submit: Ian Lance Taylor <iant@google.com>
2023-09-05all: use ^TestName$ regular pattern for invoking a single testDmitri Shuralyov
Use ^ and $ in the -run flag regular expression value when the intention is to invoke a single named test. This removes the reliance on there not being another similarly named test to achieve the intended result. In particular, package syscall has tests named TestUnshareMountNameSpace and TestUnshareMountNameSpaceChroot that both trigger themselves setting GO_WANT_HELPER_PROCESS=1 to run alternate code in a helper process. As a consequence of overlap in their test names, the former was inadvertently triggering one too many helpers. Spotted while reviewing CL 525196. Apply the same change in other places to make it easier for code readers to see that said tests aren't running extraneous tests. The unlikely cases of -run=TestSomething intentionally being used to run all tests that have the TestSomething substring in the name can be better written as -run=^.*TestSomething.*$ or with a comment so it is clear it wasn't an oversight. Change-Id: Iba208aba3998acdbf8c6708e5d23ab88938bfc1e Reviewed-on: https://go-review.googlesource.com/c/go/+/524948 Reviewed-by: Tobias Klauser <tobias.klauser@gmail.com> Auto-Submit: Dmitri Shuralyov <dmitshur@golang.org> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com> Reviewed-by: Kirill Kolyshkin <kolyshkin@gmail.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2023-04-21flag: panic if a flag is defined after being setKeith Randall
As part of developing #57411, we ran into cases where a flag was defined in one package init and Set in another package init, and there was no init ordering implied by the spec between those two packages. Changes in initialization ordering as part of #57411 caused a Set to happen before the definition, which makes the Set silently fail. This CL makes the Set fail loudly in that situation. Currently Set *does* fail kinda quietly in that situation, in that it returns an error. (It seems that no one checks the error from Set, at least for string flags.) Ian suggsted that instead we panic at the definition site if there was previously a Set called on that (at the time undefined) flag. So Set on an undefined flag is ok and returns an error (as before), but defining a flag which has already been Set causes a panic. (The API for flag definition has no way to return an error, and does already panic in some situations like a duplicate definition.) Update #57411 Change-Id: I39b5a49006f9469de0b7f3fe092afe3a352e4fcb Reviewed-on: https://go-review.googlesource.com/c/go/+/480215 Run-TryBot: Keith Randall <khr@golang.org> Reviewed-by: Ian Lance Taylor <iant@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Keith Randall <khr@google.com>
2023-03-16flag: add BoolFunc; FlagSet.BoolFuncCarl Johnson
Fixes #53747 Based on CL 416514 Change-Id: I1ff79c6290b06dfa8672a473045e8fe80c22afcf GitHub-Last-Rev: 74fba9b3096487c04c8dc1f2237f67f3558212f1 GitHub-Pull-Request: golang/go#59013 Reviewed-on: https://go-review.googlesource.com/c/go/+/476015 Run-TryBot: Ian Lance Taylor <iant@google.com> Run-TryBot: Ian Lance Taylor <iant@golang.org> Auto-Submit: Ian Lance Taylor <iant@google.com> Reviewed-by: Cherry Mui <cherryyz@google.com> Reviewed-by: Rob Pike <r@golang.org> Reviewed-by: Ian Lance Taylor <iant@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
2022-10-26flag: clarify that the main func at pkg.go.dev is part of a testing suiteZeke Lu
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 <iant@google.com> Run-TryBot: Rob Pike <r@golang.org> Reviewed-by: Ian Lance Taylor <iant@google.com> Reviewed-by: Rob Pike <r@golang.org> Auto-Submit: Ian Lance Taylor <iant@google.com> Reviewed-by: Heschi Kreinick <heschi@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
2022-10-17flag: remove "// BUG" commentZamicol
Remove a vestigial " // BUG" comment as there is no bug in the relevant code section and comment predated other changes. Also removed a needless allocation and conformed to the "v, ok := a[x]" standard convention. Tests are passing. Change-Id: Id28ad1baf77447052b54b341f018e573bac0c11a GitHub-Last-Rev: 26084698bfc0972d7e0fec0de4f31cc87e3a5f7a GitHub-Pull-Request: golang/go#56210 Reviewed-on: https://go-review.googlesource.com/c/go/+/442815 Reviewed-by: Ian Lance Taylor <iant@google.com> Reviewed-by: David Chase <drchase@google.com> Auto-Submit: Ian Lance Taylor <iant@google.com> Run-TryBot: Ian Lance Taylor <iant@google.com> Reviewed-by: Rob Pike <r@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org>
2022-09-19flag: test IsBoolFlag when creating the usage messageRob Pike
Although I can't think of any reason to do this, it is possible for a user-defined flag to implement IsBoolFlag but return "false". This is nuts because checking the interface is satisfied should obviously be sufficient, but the documentation kinda implies it's not. And if you try this, you'll discover that the usage message ignores the return value even though the rest of the package plays nice. Bother. So we fix it, as the fix is trivial: call the method when creating the usage message. Fixes #53473 Change-Id: I1ac80a876ad5626eebfc5ef6cb972cd3007afaad Reviewed-on: https://go-review.googlesource.com/c/go/+/431102 Reviewed-by: Cherry Mui <cherryyz@google.com> Run-TryBot: Ian Lance Taylor <iant@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@google.com>
2022-09-06flag: use strings.Buildercuiweixie
Change-Id: Iee846c4ac0f111ff97aa618dd42f6b2d14aa4342 Reviewed-on: https://go-review.googlesource.com/c/go/+/428259 TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com> Auto-Submit: Ian Lance Taylor <iant@google.com> Run-TryBot: Ian Lance Taylor <iant@google.com>
2022-07-01flag: highlight support for double dashes in docsSebastian Gassner
Updating examples, to show that double dashes are also permitted. This has been easy to miss previously. Change-Id: Ib67b4e39fea90ef4cb9e894709c53baedfc18fc2 GitHub-Last-Rev: f7df57b646d6412c1346e85c3a7353a8df41afc6 GitHub-Pull-Request: golang/go#53628 Reviewed-on: https://go-review.googlesource.com/c/go/+/415374 Reviewed-by: Rob Pike <r@golang.org> Reviewed-by: Ian Lance Taylor <iant@google.com> Auto-Submit: Ian Lance Taylor <iant@google.com> Reviewed-by: David Chase <drchase@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: Ian Lance Taylor <iant@google.com>
2022-04-11all: gofmt main repoRuss Cox
[This CL is part of a sequence implementing the proposal #51082. The design doc is at https://go.dev/s/godocfmt-design.] Run the updated gofmt, which reformats doc comments, on the main repository. Vendored files are excluded. For #51082. Change-Id: I7332f099b60f716295fb34719c98c04eb1a85407 Reviewed-on: https://go-review.googlesource.com/c/go/+/384268 Reviewed-by: Jonathan Amsterdam <jba@google.com> Reviewed-by: Ian Lance Taylor <iant@golang.org>
2022-04-01flag: recover panic when calling String on zero value in PrintDefaultsAndrew Gerrand
When printing the usage message, recover panics when calling String methods on reflect-constructed flag.Value zero values. Collect the panic messages and include them at the end of the PrintDefaults output so that the programmer knows to fix the panic. Fixes #28667 Change-Id: Ic4378a5813a2e26f063d5580d678add65ece8f97 Reviewed-on: https://go-review.googlesource.com/c/go/+/396574 Run-TryBot: Andrew Gerrand <adg@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Rob Pike <r@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org> Auto-Submit: Ian Lance Taylor <iant@golang.org> Trust: Andrew Gerrand <adg@golang.org>
2022-03-15all: untab /* */ doc commentsRuss Cox
A long time ago, gofmt insisted on inserting tabs in /* */ comments at the top level of the file, like this: /* Package doc comment. */ package p Gofmt still insists on the tab for comments not at top level, but it has relaxed the rules about top-level comments. A few very old doc comments are indented, left over from the old rule. We are considering formatting doc comments, and so to make everything consistent, standardize on unindented doc comments by removing tabs in the few doc comments that are still indented this way. Also update some cmd/gofmt testdata to match. Change-Id: I293742e39b52f8a48ec41f72ca4acdafa7ce43bc Reviewed-on: https://go-review.googlesource.com/c/go/+/384261 Trust: Russ Cox <rsc@golang.org> Run-TryBot: Russ Cox <rsc@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
2022-03-10flag: add TextVar functionJoe Tsai
The TextVar function makes it easier to integrate the flag package with any Go type that implements encoding.Text{Marshaler,Unmarshaler}. Fixes #45754 Change-Id: Id23c37d59cf8c9699a7943a22ce27a45eb685c0f Reviewed-on: https://go-review.googlesource.com/c/go/+/313329 Trust: Joseph Tsai <joetsai@digital-static.net> Reviewed-by: Ian Lance Taylor <iant@golang.org> Run-TryBot: Joseph Tsai <joetsai@digital-static.net> TryBot-Result: Gopher Robot <gobot@golang.org>
2022-03-07flag: make tests silentDaniel Martí
A few of the tests were printing garbage to stderr, since FlagSet's default Output is os.Stderr: $ go test flag provided but not defined: -x invalid value "1" for flag -v: test error Usage of test: flag needs an argument: -b Usage of test: -b usage PASS ok flag 0.008s Add the remaining SetOutput(io.Discard) method calls. Note that TestUserDefinedFunc was a tricky one. Even with the added SetOutput calls, the last part of the test would still print usage text to stderr. It took me a while to figure out the problem was copying FlagSet. I've filed go.dev/issue/51507 to record this particular sharp edge, and the test code now avoids making FlagSet copies to avoid the bug. Change-Id: I323f24091b98386312aa72df3eb890af6625628d Reviewed-on: https://go-review.googlesource.com/c/go/+/390234 Trust: Daniel Martí <mvdan@mvdan.cc> Run-TryBot: Daniel Martí <mvdan@mvdan.cc> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
2021-12-13all: gofmt -w -r 'interface{} -> any' srcRuss Cox
And then revert the bootstrap cmd directories and certain testdata. And adjust tests as needed. Not reverting the changes in std that are bootstrapped, because some of those changes would appear in API docs, and we want to use any consistently. Instead, rewrite 'any' to 'interface{}' in cmd/dist for those directories when preparing the bootstrap copy. A few files changed as a result of running gofmt -w not because of interface{} -> any but because they hadn't been updated for the new //go:build lines. Fixes #49884. Change-Id: Ie8045cba995f65bd79c694ec77a1b3d1fe01bb09 Reviewed-on: https://go-review.googlesource.com/c/go/+/368254 Trust: Russ Cox <rsc@golang.org> Run-TryBot: Russ Cox <rsc@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org>
2021-10-26all: use reflect.{Pointer,PointerTo}Cuong Manh Le
Updates #47651 Updates #48665 Change-Id: I69a87b45a5cad7a07fbd855040cd9935cf874554 Reviewed-on: https://go-review.googlesource.com/c/go/+/358454 Trust: Cuong Manh Le <cuong.manhle.vn@gmail.com> Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2021-04-05flag: use strings.Builder instead of concatenating stringsJames Fennell
There is a single function in the flag package whose implementation uses string concatenation instead of the recommended strings.Builder. The function was last touched before strings.Builder was introduced in Go 1.10, which explains the old style code. This PR updates the implementation. Fixes #45392 Change-Id: Id2d8f1788765a0c4faaeb1e6870914f72b3c8442 GitHub-Last-Rev: 0e12fe304593afc627fc4f1597670efd354809b0 GitHub-Pull-Request: golang/go#45393 Reviewed-on: https://go-review.googlesource.com/c/go/+/307329 Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org> Trust: Josh Bleecher Snyder <josharian@gmail.com>
2021-03-10flag: panic if flag name begins with - or contains =KimMachineGun
Fixes #41792 Change-Id: I9b4aae8a899e3c3ac9532d27932d275cfb1fab48 GitHub-Last-Rev: f06b1e17674bf77bdc2d3e798df4c4379748c8d2 GitHub-Pull-Request: golang/go#42737 Reviewed-on: https://go-review.googlesource.com/c/go/+/271788 Reviewed-by: Emmanuel Odeke <emmanuel@orijtech.com> Reviewed-by: Rob Pike <r@golang.org> Run-TryBot: Emmanuel Odeke <emmanuel@orijtech.com> TryBot-Result: Go Bot <gobot@golang.org> Trust: Rob Pike <r@golang.org>
2020-10-20all: update references to symbols moved from io/ioutil to ioRuss Cox
The old ioutil references are still valid, but update our code to reflect best practices and get used to the new locations. Code compiled with the bootstrap toolchain (cmd/asm, cmd/dist, cmd/compile, debug/elf) must remain Go 1.4-compatible and is excluded. Also excluded vendored code. For #41190. Change-Id: I6d86f2bf7bc37a9d904b6cee3fe0c7af6d94d5b1 Reviewed-on: https://go-review.googlesource.com/c/go/+/263142 Trust: Russ Cox <rsc@golang.org> Run-TryBot: Russ Cox <rsc@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Emmanuel Odeke <emm.odeke@gmail.com>
2020-09-16flag: add FuncCarl Johnson
Fixes #39557 Change-Id: Ida578f7484335e8c6bf927255f75377eda63b563 GitHub-Last-Rev: b97294f7669c24011e5b093179d65636512a84cd GitHub-Pull-Request: golang/go#39880 Reviewed-on: https://go-review.googlesource.com/c/go/+/240014 Reviewed-by: Russ Cox <rsc@golang.org> Trust: Ian Lance Taylor <iant@golang.org>
2020-04-03flag: fix TestExitCode on Plan 9David du Colombier
CL 221427 added TestExitCode. This test is failing on Plan 9 because ExitCode is always equal to 1 on error since Plan 9 use error strings. This change fixes TestExitCode by checking that ExitCode is equal to 1 on error instead of the specific value. Fixes #38237. Change-Id: Ie269722e731e275e5bfc51644c1fa6be76525f1f Reviewed-on: https://go-review.googlesource.com/c/go/+/227158 Run-TryBot: David du Colombier <0intro@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Bryan C. Mills <bcmills@google.com>
2020-04-03flag: exit 0 when -h or -help invoked but undefinedShang Jian Ding
flag treats -h or -help as a special case to print a nice help message, but exit with a status code of 2. This update makes that status code 0. Fixes #37533 Change-Id: I7e0bd29944ce46607fb7cfc6740734f7444a151a GitHub-Last-Rev: 83f64d757bc3a9957c49caa5de74d05a96724771 GitHub-Pull-Request: golang/go#37530 Reviewed-on: https://go-review.googlesource.com/c/go/+/221427 Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
2020-03-03flag: changed flag variable name in package doc, for clarityyuz
Changed the flag variable name to nFlag instead of flagname, because flagname was confusing. Change-Id: I20dd4c4b4f605395d427a125ba4fd14580e5d766 Reviewed-on: https://go-review.googlesource.com/c/go/+/221678 Reviewed-by: Rob Pike <r@golang.org>
2020-02-27flag: update comment to refer to Output, not outIan Lance Taylor
The out method was renamed to Output in CL 70391 for #17628 and #21888. Fixes #37514 Change-Id: I99be47b5030ccbbf10a056df9fcc3c97cb99b015 Reviewed-on: https://go-review.googlesource.com/c/go/+/221383 Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Rob Pike <r@golang.org>
2019-11-11flag: clarify that a flag cannot be re-definedAgniva De Sarker
Fixes #31694 Change-Id: Ifb2ad2dc41c449668c0f6a4d4cfb9b583e5591f2 Reviewed-on: https://go-review.googlesource.com/c/go/+/206126 Reviewed-by: Rob Pike <r@golang.org>
2019-03-31cmd/go: further reduce init workDaniel Martí
The first biggest offender was crypto/des.init at ~1%. It's cryptographically broken and the init function is relatively expensive, which is unfortunate as both crypto/tls and crypto/x509 (and by extension, cmd/go) import it. Hide the work behind sync.Once. The second biggest offender was flag.sortFlags at just under 1%, used by the Visit flagset methods. It allocated two slices, which made a difference as cmd/go iterates over multiple flagsets during init. Use a single slice with a direct sort.Interface implementation. Another big offender is initializing global maps. Reducing this work in cmd/go/internal/imports and net/textproto gives us close to another whole 1% in saved work. The former can use map literals, and the latter can hide the work behind sync.Once. Finally, compress/flate used newHuffmanBitWriter as part of init, which allocates many objects and slices. Yet it only used one of the slice fields. Allocating just that slice saves a surprising ~0.3%, since we generated a lot of unnecessary garbage. All in all, these little pieces amount to just over 3% saved CPU time. name old time/op new time/op delta ExecGoEnv-8 3.61ms ± 1% 3.50ms ± 0% -3.02% (p=0.000 n=10+10) Updates #26775. Updates #29382. Change-Id: I915416e88a874c63235ba512617c8aef35c0ca8b Reviewed-on: https://go-review.googlesource.com/c/go/+/166459 Run-TryBot: Daniel Martí <mvdan@mvdan.cc> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2019-01-21flag: improve docs for PrintDefaults; clarify how to change output destinationAaron Cannon
The existing docs only mention that it is possible to change the output destination of PrintDefaults from the default of standard error, but fail to mention how to actually do so. This change fixes this lack by directing users to CommandLine.SetOutput. Fixes #15024 Change-Id: Ieaa7edbebd23d4ea6fa7e53d97a87143d590bdb3 Reviewed-on: https://go-review.googlesource.com/c/145203 Reviewed-by: Rob Pike <r@golang.org>
2018-10-19flag: return a consistent parse error if the flag value is invalidRob Pike
Return a consistently formatted error string that reports either a parse error or a range error. Before: invalid boolean value "3" for -debug: strconv.ParseBool: parsing "3": invalid syntax After: invalid boolean value "3" for -debug: parse error Fixes #26822 Change-Id: I60992bf23da32a4c0cf32472a8af486a3c9674ad Reviewed-on: https://go-review.googlesource.com/c/143257 Reviewed-by: Ian Lance Taylor <iant@golang.org>
2018-09-26all: use strings.ReplaceAll and bytes.ReplaceAll where applicableBrad Fitzpatrick
I omitted vendor directories and anything necessary for bootstrapping. (Tested by bootstrapping with Go 1.4) Updates #27864 Change-Id: I7d9b68d0372d3a34dee22966cca323513ece7e8a Reviewed-on: https://go-review.googlesource.com/137856 Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
2018-06-21flag: add a Value exampleTerin Stock
Change-Id: I579cc9f4f8e5be5fd6447a99614797ab7bc53611 Reviewed-on: https://go-review.googlesource.com/120175 Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
2018-06-14flag: fix headers in documentation, againDominik Honnef
Godoc expects text after a header, not code. Change-Id: I99f412ad15e10bf9cea0dbd19019ed6ce477736c Reviewed-on: https://go-review.googlesource.com/117595 Reviewed-by: Rob Pike <r@golang.org>
2018-06-07flag: removed the colon after "Usage" in the documentationhellozee
Removing the colon will make the "Usage" and "Command line flag syntax" in the docs, a header when interpreted by godoc. Fixes #25749 Change-Id: Ifc5572e171db1aaef9775b1d6c86091a8f2528fd GitHub-Last-Rev: 1b579734308cbcb96f17d945b9c7af70e259cb5b GitHub-Pull-Request: golang/go#25750 Reviewed-on: https://go-review.googlesource.com/116555 Reviewed-by: Rob Pike <r@golang.org>
2018-04-01flag: correct zero values when printing defaultsjimmyfrasche
When the flag package first begin printing nonzero defaults, the test was against a fixed set of string representations of zero values. This worked until the string representation of a time.Duration changed from "0" to "0s", causing the zero Duration to register as nonzero. The flag package then added reflect-based code that fell back to the old test. This failed to work when a nonzero default for a flag happened to be the string representation of one the original fixed set of zero values in the original test. This change removes the original test, allowing the reflect-based code to be the only deciding factor. Fixes #23543 Change-Id: I582ce554d6729e336fdd96fb27340674c15350d8 Reviewed-on: https://go-review.googlesource.com/103867 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
2018-03-28flag: document use of FlagSet name parameterIan Lance Taylor
Fixes #24225 Change-Id: I876ac1b9d3615283f7b88cfa0b965ef81a57f056 Reviewed-on: https://go-review.googlesource.com/102955 Reviewed-by: Rob Pike <r@golang.org>
2017-12-06flag: clarify comment to avoid shell syntax confusionIan Lance Taylor
Updates #22961 Change-Id: Ib2f41aefb4f6470598d8637611da5491156ea840 Reviewed-on: https://go-review.googlesource.com/82015 Reviewed-by: Rob Pike <r@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2017-10-31flag: add (*FlagSet).Name, (*FlagSet).ErrorHandling, export (*FlagSet).OutputTim Cooper
Allows code that operates on a FlagSet to know the name and error handling behavior of the FlagSet without having to call FlagSet.Init. Fixes #17628 Fixes #21888 Change-Id: Ib0fe4c8885f9ccdacf5a7fb761d5ecb23f3bb055 Reviewed-on: https://go-review.googlesource.com/70391 Run-TryBot: Ian Lance Taylor <iant@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
2017-10-17flag: simplify switch-case in isZeroValueGabriel Aszalos
Simplifies the switch statement in the isZeroValue function by merging the case branches. Change-Id: I5b27939b62808dadac0cef632567b17e0e2b9a1d Reviewed-on: https://go-review.googlesource.com/71390 Run-TryBot: Gabriel Aszalos <gabriel.aszalos@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
2017-09-28flag: align multi-line usage stringsTim Cooper
Previously, a multi-line flag usage string would not be indented with the rest of the usage strings. This made long usage strings difficult to read. For example, the usage for flag.String("A", "", "1\n2\n3") would be printed as: -A 1 2 3 But will now be printed as: -A 1 2 3 Also fixes a slight error in the FlagSet.PrintDefaults documentation. Fixes #20799 Change-Id: I4379c6b7590fdb93a2809a01046a0f6ae32c3e5d Reviewed-on: https://go-review.googlesource.com/66711 Run-TryBot: Russ Cox <rsc@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Russ Cox <rsc@golang.org>
2017-09-05flag: simplify arg logic in parseOnealexpantyukhin
Fixes #21763. Change-Id: I59ee4f24c8064df64d9ede11aac02bc7ce4995b3 Reviewed-on: https://go-review.googlesource.com/61491 Reviewed-by: Daniel Martí <mvdan@mvdan.cc> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> Run-TryBot: Daniel Martí <mvdan@mvdan.cc> TryBot-Result: Gobot Gobot <gobot@golang.org>
2017-08-29flag: document that custom usage functions are free to call os.ExitRob Pike
Some custom usage functions call it for clarity; others rely on the default behavior, which makes an explicit call redundant. Document that it's safe to be explicit. Fixes #21671. Change-Id: I08e9f47265582821cfd35995dff0c589cd85809d Reviewed-on: https://go-review.googlesource.com/59792 Reviewed-by: Dominik Honnef <dominik@honnef.co> Reviewed-by: Ian Lance Taylor <iant@golang.org>
2017-08-26all: remove some double spaces from commentsDaniel Martí
Went mainly for the ones that make no sense, such as the ones mid-sentence or after commas. Change-Id: Ie245d2c19cc7428a06295635cf6a9482ade25ff0 Reviewed-on: https://go-review.googlesource.com/57293 Reviewed-by: Ian Lance Taylor <iant@golang.org> Run-TryBot: Daniel Martí <mvdan@mvdan.cc> TryBot-Result: Gobot Gobot <gobot@golang.org>
2017-08-08flag: make default Usage prefer CommandLine's output over just os.StderrBrad Fitzpatrick
CommandLine (exported in Go 1.2) has default output of os.Stderr. Before it was exported, it made sense to have the global Usage func (the implicit usage func if CommandLine.Usage is nil) hard-code os.Stderr has its output. But once CommandLine was exported, Usage should use it if provided. Fixes #20998 Change-Id: I9e1c0415a563a982634b9808199c9ee175d72f4c Reviewed-on: https://go-review.googlesource.com/48390 Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Rob Pike <r@golang.org>
2017-03-21flag: validate Int and Uint values to be in rangeBrad Fitzpatrick
Fixes #19230 Change-Id: I38df9732b88f0328506e74f1a46f52adf47db1e5 Reviewed-on: https://go-review.googlesource.com/38419 Reviewed-by: Robert Griesemer <gri@golang.org> Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
2016-10-26flag: arrange for FlagSet.Usage to be non-nil by defaultRuss Cox
This allows callers to invoke f.Usage() themselves and get the default usage handler instead of a panic (from calling a nil function). Fixes #16955. Change-Id: Ie337fd9e1f85daf78c5eae7b5c41d5ad8c1f89bf Reviewed-on: https://go-review.googlesource.com/31576 Run-TryBot: Russ Cox <rsc@golang.org> Reviewed-by: Rob Pike <r@golang.org>
2016-09-10flag: use strconv instead of fmt in values' String funcsbogem
The existing implementation of flag values with fmt package uses more memory and works slower than the implementation with strconv package. Change-Id: I9e749179f66d5c50cafe98186641bcdbc546d2db Reviewed-on: https://go-review.googlesource.com/28914 Reviewed-by: Ian Lance Taylor <iant@golang.org> Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
2016-08-23flag: improve comment for calling String with zero valueIan Lance Taylor
Update #16694. Change-Id: Id6be1535d8a146b3dac3bee429ce407a51272032 Reviewed-on: https://go-review.googlesource.com/27634 Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Rob Pike <r@golang.org>
2016-08-23flag: document that Value.String must work on the zero valueIan Lance Taylor
Otherwise flag.PrintDefaults will fail when it tries to determine whether the default is the zero value. Fixes #16694. Change-Id: I253fbf11ffc0a9069fd48c2c3cf3074df53e3a03 Reviewed-on: https://go-review.googlesource.com/27003 Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2016-05-31flag: recognize "0s" as the zero value for a flag.DurationIan Lance Taylor
Implemented by using a reflect-based approach to recognize the zero value of any non-interface type that implements flag.Value. Interface types will fall back to the old code. Fixes #15904. Change-Id: I594c3bfb30e9ab1aca3e008ef7f70be20aa41a0b Reviewed-on: https://go-review.googlesource.com/23581 Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Rob Pike <r@golang.org>
2016-04-21flag: update test case (fix build)Robert Griesemer
Change-Id: I2275dc703be4fda3feedf76483148eab853b43b8 Reviewed-on: https://go-review.googlesource.com/22360 Run-TryBot: Robert Griesemer <gri@golang.org> Reviewed-by: Rob Pike <r@golang.org>