Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(8983)

Issue 842041: code review 842041: Flags: add user-defined flag types. The change is reall... (Closed)

Can't Edit
Can't Publish+Mail
Start Review
Created:
14 years ago by r
Modified:
14 years ago
Reviewers:
CC:
rsc, golang-dev
Visibility:
Public.

Description

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) }

Patch Set 1 #

Patch Set 2 : code review 842041: Flags: add user-defined flag types. The change is reall... #

Patch Set 3 : code review 842041: Flags: add user-defined flag types. The change is reall... #

Unified diffs Side-by-side diffs Delta from patch set Stats (+64 lines, -45 lines) Patch
M src/pkg/flag/flag.go View 1 23 chunks +45 lines, -45 lines 0 comments Download
M src/pkg/flag/flag_test.go View 1 chunk +19 lines, -0 lines 0 comments Download

Messages

Total messages: 3
r
Hello golang-dev@googlegroups.com, I'd like you to review this change.
14 years ago (2010-03-30 00:01:21 UTC) #1
rsc1
LGTM
14 years ago (2010-03-30 00:06:14 UTC) #2
r
14 years ago (2010-03-30 00:37:25 UTC) #3
*** Submitted as http://code.google.com/p/go/source/detail?r=6070517caba0 ***

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
http://codereview.appspot.com/842041
Sign in to reply to this message.

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b