Skip to content

Commit

Permalink
Fix enum values.
Browse files Browse the repository at this point in the history
  • Loading branch information
alecthomas committed Jul 8, 2014
1 parent 4ab784b commit c94b963
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 10 deletions.
8 changes: 4 additions & 4 deletions flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,13 @@ func (f *flagGroup) init() error {

func (f *flagGroup) parse(tokens tokens, ignoreRequired bool) (tokens, error) {
// Track how many required flags we've seen.
required := make(map[string]struct{})
required := make(map[string]bool)
// Keep track of any flags that we need to initialise with defaults.
defaults := make(map[string]struct{})
defaults := make(map[string]bool)
for k, flag := range f.long {
defaults[k] = struct{}{}
defaults[k] = true
if !ignoreRequired && flag.needsValue() {
required[k] = struct{}{}
required[k] = true
}
}

Expand Down
4 changes: 2 additions & 2 deletions parsers.go
Original file line number Diff line number Diff line change
Expand Up @@ -264,11 +264,11 @@ func (p *parserMixin) URLListVar(target *[]*url.URL) {
// Enum allows a value from a set of options.
func (p *parserMixin) Enum(options ...string) (target *string) {
target = new(string)
p.EnumVar(target, options...)
p.EnumVar(&target, options...)
return
}

// EnumVar allows a value from a set of options.
func (p *parserMixin) EnumVar(target *string, options ...string) {
func (p *parserMixin) EnumVar(target **string, options ...string) {
p.SetValue(newEnumFlag(target, options...))
}
7 changes: 3 additions & 4 deletions values.go
Original file line number Diff line number Diff line change
Expand Up @@ -420,16 +420,15 @@ type enumValue struct {
options []string
}

func newEnumFlag(target *string, options ...string) *enumValue {
value := new(string)
func newEnumFlag(target **string, options ...string) *enumValue {
return &enumValue{
value: value,
value: *target,
options: options,
}
}

func (a *enumValue) String() string {
return *a.value + " [" + strings.Join(a.options, "|") + "]"
return *a.value
}

func (a *enumValue) Set(value string) error {
Expand Down

0 comments on commit c94b963

Please sign in to comment.