From e7b1833f53b63f3f43aeebc77f37c348d82d5c04 Mon Sep 17 00:00:00 2001 From: Jesse Szwedko Date: Thu, 8 Sep 2016 21:10:46 -0700 Subject: [PATCH] Dereference `Flag`s if they are pointers When checking if environment variables are set. We don't support pointer flags currently (though this is the default in the `v2` branch), but this fixes #516 --- context.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/context.go b/context.go index 15570c5..492a742 100644 --- a/context.go +++ b/context.go @@ -79,7 +79,12 @@ func (c *Context) IsSet(name string) bool { return } - envVarValue := reflect.ValueOf(f).FieldByName("EnvVar") + val := reflect.ValueOf(f) + if val.Kind() == reflect.Ptr { + val = val.Elem() + } + + envVarValue := val.FieldByName("EnvVar") if !envVarValue.IsValid() { return }