From dd58503eaf60b9d66abb69a1f1ba1f9388a6c817 Mon Sep 17 00:00:00 2001 From: David Symonds Date: Tue, 17 Apr 2012 16:37:35 +1000 Subject: [PATCH] [release-branch.go1] flag: update style. MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit ««« backport 059ba0d0dc6a flag: update style. R=golang-dev, r, r CC=golang-dev https://golang.org/cl/6051044 »»» --- src/pkg/flag/flag.go | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/pkg/flag/flag.go b/src/pkg/flag/flag.go index c28d0e7207..f0842a18a2 100644 --- a/src/pkg/flag/flag.go +++ b/src/pkg/flag/flag.go @@ -7,9 +7,11 @@ Usage: - Define flags using flag.String(), Bool(), Int(), etc. Example: + Define flags using flag.String(), Bool(), Int(), etc. + + This declares an integer flag, -flagname, stored in the pointer ip, with type *int. import "flag" - var ip *int = flag.Int("flagname", 1234, "help message for flagname") + var ip = flag.Int("flagname", 1234, "help message for flagname") If you like, you can bind the flag to a variable using the Var() functions. var flagvar int func init() { @@ -26,8 +28,8 @@ Flags may then be used directly. If you're using the flags themselves, they are all pointers; if you bind to variables, they're values. - fmt.Println("ip has value ", *ip); - fmt.Println("flagvar has value ", flagvar); + fmt.Println("ip has value ", *ip) + fmt.Println("flagvar has value ", flagvar) After parsing, the arguments after the flag are available as the slice flag.Args() or individually as flag.Arg(i). -- 2.50.0