Skip to content

Commit

Permalink
Ensure that EnvVar struct field exists before interrogating it
Browse files Browse the repository at this point in the history
Otherwise you end up with `<invalid Value>` which, in practice, would
probably work, but this is cleaner.
  • Loading branch information
jszwedko committed Aug 1, 2016
1 parent d604690 commit 168c954
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions context.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,12 @@ func (c *Context) IsSet(name string) bool {
return
}

envVars := reflect.ValueOf(f).FieldByName("EnvVar").String()
envVarValue := reflect.ValueOf(f).FieldByName("EnvVar")
if !envVarValue.IsValid() {
return
}

eachName(envVars, func(envVar string) {
eachName(envVarValue.String(), func(envVar string) {
envVar = strings.TrimSpace(envVar)
if envVal := os.Getenv(envVar); envVal != "" {
c.setFlags[name] = true
Expand Down

0 comments on commit 168c954

Please sign in to comment.