From 168c95418e66e019fe17b8f4f5c45aa62ff80e23 Mon Sep 17 00:00:00 2001 From: Jesse Szwedko Date: Sun, 31 Jul 2016 20:09:57 -0700 Subject: [PATCH] Ensure that EnvVar struct field exists before interrogating it Otherwise you end up with `` which, in practice, would probably work, but this is cleaner. --- context.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/context.go b/context.go index 5ea4f8f..15570c5 100644 --- a/context.go +++ b/context.go @@ -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