diff options
| author | Alex Ogier <[email protected]> | 2012-12-19 04:23:25 -0500 |
|---|---|---|
| committer | Alex Ogier <[email protected]> | 2012-12-19 04:23:25 -0500 |
| commit | bc8eb13c45bf419dbf31b974e9931e5ab049cada (patch) | |
| tree | 4c2731f0f02205a55bed85df370ef4bd30af522e /README.md | |
| parent | 929490184252ab7e27a45d03738303e99df438f7 (diff) | |
Merge changes from Go's standard flag library.
Up to date through e7cd0a82d669. Relevant changesets:
https://code.google.com/p/go/source/detail?r=059ba0d0dc6a27d115c619ff8bcd646335eed67f
https://code.google.com/p/go/source/detail?r=64a249c65d510184268160bf595cf3db478a296e
https://code.google.com/p/go/source/detail?r=6ca4825bc86760d43392469c0af266bb858fc77b
Diffstat (limited to 'README.md')
| -rw-r--r-- | README.md | 10 |
1 files changed, 6 insertions, 4 deletions
@@ -40,7 +40,9 @@ Most code never instantiates this struct directly, and instead uses functions such as String(), BoolVar(), and Var(), and is therefore unaffected. -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. ``` go var ip *int = flag.Int("flagname", 1234, "help message for flagname") @@ -76,13 +78,13 @@ 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. ``` go -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). -The arguments are indexed from 0 up to flag.NArg(). +The arguments are indexed from 0 through flag.NArg()-1. The pflag package also defines some new functions that are not in flag, that give one-letter shorthands for flags. You can use these by appending |
