1
0
mirror of https://github.com/golang/go synced 2024-11-21 20:04:44 -07:00
The Go programming language
Go to file
Rob Pike 570af81e19 Flags: add user-defined flag types. The change is really no code; it's just publishing
the set() method and add() functions.  But we rename add() to Var() for consistency.
Also rename FlagValue to Value for simplicity.

Also, delete the check for multiple settings for a flag.  This makes it possible to
define a flag that collects values, such as into a slice of strings.

type flagVar []string

func (f *flagVar) String() string {
	return fmt.Sprint(v)
}

func (f *flagVar) Set(value string) bool {
	if v == nil {
		v = make(flagVar, 1)
	} else {
		nv := make(flagVar, len(v)+1)
		copy(nv, v)
		v = nv
	}
	v[len(v)-1] = value
	return true
}

var v flagVar

func main() {
	flag.Var(&v, "testV", "multiple values build []string")
	flag.Parse()
	fmt.Printf("v = %v\n", v)
}

R=rsc
CC=golang-dev
https://golang.org/cl/842041
2010-03-29 17:37:22 -07:00
doc spec: typo in switch sample code, missing semicolon 2010-03-29 13:12:08 +11:00
include Fix *l/*c -V flag segfault 2010-02-08 11:53:27 -08:00
lib godoc: show relative file names without leading '/' (per r's request) 2010-03-24 16:28:59 -07:00
misc misc/bbedit: support for cmplx, real, imag 2010-03-16 13:26:34 -07:00
pkg more description 2009-10-15 23:08:46 -07:00
src Flags: add user-defined flag types. The change is really no code; it's just publishing 2010-03-29 17:37:22 -07:00
test gc: bug265 2010-03-29 15:27:59 -07:00
.hgignore runtime: add GOROOT and Version 2010-03-16 23:10:33 -07:00
.hgtags release.2010-03-22 part two 2010-03-23 14:18:57 +11:00
AUTHORS A+C: add Kyle Consalus (individual CLA) 2010-03-20 22:37:53 -07:00
CONTRIBUTORS A+C: add Kyle Consalus (individual CLA) 2010-03-20 22:37:53 -07:00
favicon.ico add a favicon plus a couple of hi-res versions of gordon 2009-10-26 10:13:07 -07:00
LICENSE Add an explicit patent grant to the Go license. 2010-01-25 15:39:32 -08:00
README add a README file, so that if someone finds a 2009-11-08 09:57:37 -08:00

This is the source code repository for the Go programming language.  

For documentation about how to install and use Go,
visit http://golang.org/ or load doc/install.html in your web browser.

After installing Go, you can view a nicely formatted
doc/install.html by running godoc --http=:6060
and then visiting http://localhost:6060/doc/install.html.

Unless otherwise noted, the Go source files are distributed
under the BSD-style license found in the LICENSE file.