summaryrefslogtreecommitdiff
path: root/src/flag
Commit message (Collapse)AuthorAgeFilesLines
* flag: arrange for FlagSet.Usage to be non-nil by defaultRuss Cox2016-10-262-6/+16
| | | | | | | | | | | | 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>
* flag: use strconv instead of fmt in values' String funcsbogem2016-09-101-7/+7
| | | | | | | | | | | | 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>
* flag: improve comment for calling String with zero valueIan Lance Taylor2016-08-231-1/+2
| | | | | | | | | | 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>
* flag: document that Value.String must work on the zero valueIan Lance Taylor2016-08-231-0/+1
| | | | | | | | | | | | | 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>
* flag: recognize "0s" as the zero value for a flag.DurationIan Lance Taylor2016-05-312-3/+18
| | | | | | | | | | | | | | 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>
* flag: update test case (fix build)Robert Griesemer2016-04-211-1/+1
| | | | | | | 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>
* all: single space after period.Brad Fitzpatrick2016-03-021-6/+6
| | | | | | | | | | | | | | | | | | | | The tree's pretty inconsistent about single space vs double space after a period in documentation. Make it consistently a single space, per earlier decisions. This means contributors won't be confused by misleading precedence. This CL doesn't use go/doc to parse. It only addresses // comments. It was generated with: $ perl -i -npe 's,^(\s*// .+[a-z]\.) +([A-Z]),$1 $2,' $(git grep -l -E '^\s*//(.+\.) +([A-Z])') $ go test go/doc -update Change-Id: Iccdb99c37c797ef1f804a94b22ba5ee4b500c4f7 Reviewed-on: https://go-review.googlesource.com/20022 Reviewed-by: Rob Pike <r@golang.org> Reviewed-by: Dave Day <djd@golang.org> Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
* all: make copyright headers consistent with one space after periodBrad Fitzpatrick2016-03-011-1/+1
| | | | | | | | | | | | | | | | | | | | | | This is a subset of https://golang.org/cl/20022 with only the copyright header lines, so the next CL will be smaller and more reviewable. Go policy has been single space after periods in comments for some time. The copyright header template at: https://golang.org/doc/contribute.html#copyright also uses a single space. Make them all consistent. Change-Id: Icc26c6b8495c3820da6b171ca96a74701b4a01b0 Reviewed-on: https://go-review.googlesource.com/20111 Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org> Reviewed-by: Matthew Dempsky <mdempsky@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org>
* flag: add comment stating that Set is called in sequence across the command lineRob Pike2015-07-161-0/+2
| | | | | | | | No code changes. Change-Id: I3b78b1048318a4b80747fde8cab919282fc444a8 Reviewed-on: https://go-review.googlesource.com/12285 Reviewed-by: Andrew Gerrand <adg@golang.org>
* flag: Clarifies docs for Arg(int) and FlagSet.Arg(int)Hariharan Srinath2015-07-121-2/+4
| | | | | | | | | | | | | Adds the clarification that these functions return empty string if the requested element is not available Added fullstops Fixes #11664 Change-Id: I84173862bc785240f7d3ee75a5023673264d172b Reviewed-on: https://go-review.googlesource.com/12061 Reviewed-by: Rob Pike <r@golang.org>
* flag: Describe the ErrorHandling enum values.Aaron Jacobs2015-06-051-4/+5
| | | | | | | | | | | ContinueOnError is particularly confusing, because it causes FlagSet.Parse to return as soon as it sees an error. I gather that the intent is "continue the program" rather than "continue parsing", compared to exiting or panicking. Change-Id: I27370ce1f321ea4debcee5b03faff3532495c71a Reviewed-on: https://go-review.googlesource.com/10740 Reviewed-by: Rob Pike <r@golang.org>
* flag: Fix up a package comment a bit.Aaron Jacobs2015-05-191-1/+1
| | | | | | | | | I think "the flag" was a typo, and the word "after" was repetitive. Change-Id: I81c034ca11a3a778ff1eb4b3af5b96bc525ab985 Reviewed-on: https://go-review.googlesource.com/10195 Reviewed-by: Rob Pike <r@golang.org> Reviewed-by: Andrew Gerrand <adg@golang.org>
* all: use "reports whether" in place of "returns true if(f)"Josh Bleecher Snyder2015-03-181-1/+1
| | | | | | | | Comment changes only. Change-Id: I56848814564c4aa0988b451df18bebdfc88d6d94 Reviewed-on: https://go-review.googlesource.com/7721 Reviewed-by: Rob Pike <r@golang.org>
* flag: use four spaces before tab, not threeRuss Cox2015-03-122-9/+9
| | | | | | | | | | | Four spaces is what works well for both 4- and 8-space tab stops. Screen with fixed-width font and 4-space tab stops: http://imgur.com/lps5Lbb Change-Id: I7d2b813d674c3e0a68f79d63bc5d5ec5bd4f87bb Reviewed-on: https://go-review.googlesource.com/7503 Reviewed-by: Rob Pike <r@golang.org>
* flag: nicer usage messagesRob Pike2015-03-122-8/+138
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Make PrintDefaults print an easier-to-read format, and allow the user to control it a bit by putting a hint into the usage string. Here is the new doc comment for PrintDefaults, which does the work: PrintDefaults prints, to standard error unless configured otherwise, a usage message showing the default settings of all defined command-line flags. For an integer valued flag x, the default output has the form -x int usage-message-for-x (default 7) The usage message will appear on a separate line except for single- letter boolean flags. Boolean flags omit the type, since they can be used without an actual value, and the parenthetical default is omitted if the default is the zero value for the type. The type, here int, can be replaced by a string of the user's choosing by placing in the usage string for the flag a back-quoted name; the first such item in the message is taken to be a parameter name to show in the message and the back quotes are stripped from the message when displayed. For instance, given flag.String("I", "", "search `directory` for include files") the output will be -I directory search directory for include files. Given A = flag.Bool("A", false, "for bootstrapping, allow 'any' type") B = flag.Bool("Alongflagname", false, "disable bounds checking") C = flag.Bool("C", true, "a boolean defaulting to true") D = flag.String("D", "", "set relative `path` for local imports") F = flag.Float64("F", 2.7, "a non-zero float") G = flag.Float64("G", 0, "a float that defaults to zero") N = flag.Int("N", 27, "a non-zero int") Z = flag.Int("Z", 0, "an int that defaults to zero") T = flag.Duration("deltaT", 0, "a duration") the old output was -A=false: for bootstrapping, allow 'any' type -Alongflagname=false: disable bounds checking -C=true: a boolean defaulting to true -D="": set relative `path` for local imports -F=2.7: a non-zero float -G=0: a float that defaults to zero -N=27: a non-zero int -Z=0: an int that defaults to zero -deltaT=0: a duration and the new output is -A for bootstrapping, allow 'any' type -Alongflagname disable bounds checking -C a boolean defaulting to true (default true) -D path set relative path for local imports -F float a non-zero float (default 2.7) -G float a float that defaults to zero -N int a non-zero int (default 27) -Z int an int that defaults to zero -deltaT duration a duration Change-Id: I54ab3cd5610d551422b004d95ab78305e06a395d Reviewed-on: https://go-review.googlesource.com/7330 Reviewed-by: Andrew Gerrand <adg@golang.org> Reviewed-by: Russ Cox <rsc@golang.org>
* flag: Check for Set errorMichalis Kargakis2014-12-221-1/+3
| | | | | | | | | | | Check for Set error when a boolean flag isn't explicitly given a value. Fixes #9345 Change-Id: I97a1289f8cf27567d1a726ebe5ef167c800f357c Reviewed-on: https://go-review.googlesource.com/1897 Reviewed-by: Andrew Gerrand <adg@golang.org> Reviewed-by: Rob Pike <r@golang.org>
* flag: Some idiomatic fixesMichalis Kargakis2014-12-211-9/+9
| | | | | | | | Make golint a bit happier Change-Id: I8a14342f3e492e92bf5efa611f9ef91176624031 Reviewed-on: https://go-review.googlesource.com/1891 Reviewed-by: Minux Ma <minux@golang.org>
* flag: roll back 156390043 (flag setting)Rob Pike2014-10-202-89/+0
| | | | | | | | | | Shell scripts depend on the old behavior too often. It's too late to make this change. LGTM=bradfitz R=rsc, bradfitz CC=golang-codereviews https://golang.org/cl/161890044
* flag: disallow setting flags multiple timesRob Pike2014-10-192-0/+90
| | | | | | | | | | | | | | | This is a day 1 error in the flag package: It did not check that a flag was set at most once on the command line. Because user-defined flags may have more general properties, the check applies only to the standard flag types in this package: bool, string, etc. Fixes #8960. LGTM=bradfitz R=golang-codereviews, bradfitz CC=golang-codereviews https://golang.org/cl/156390043
* flag: allow CommandLine's Usage function to be setRob Pike2014-09-262-6/+19
| | | | | | | | | Fixes #7779. LGTM=rsc R=golang-codereviews, rsc CC=golang-codereviews https://golang.org/cl/147210043
* build: move package sources from src/pkg to srcRuss Cox2014-09-084-0/+1323
Preparation was in CL 134570043. This CL contains only the effect of 'hg mv src/pkg/* src'. For more about the move, see golang.org/s/go14nopkg.