From 983228e2f0f2d60c3f989b5147950a1ca639fedc Mon Sep 17 00:00:00 2001 From: Naveen Gogineni Date: Mon, 26 Jun 2023 12:34:56 +0530 Subject: [PATCH] Fix more tests --- context.go | 5 +++++ flag_impl.go | 8 +++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/context.go b/context.go index 9b46816d10..6d932cbf39 100644 --- a/context.go +++ b/context.go @@ -4,6 +4,7 @@ import ( "context" "flag" "fmt" + "log" "strings" ) @@ -156,6 +157,10 @@ func (cCtx *Context) Value(name string) interface{} { if g, ok := f.(ValueGetter); ok { return g.GetFlagValue().Get() } + if g, ok := f.(flag.Getter); ok { + log.Printf("%v", g.Get()) + return g.Get() + } } return nil } diff --git a/flag_impl.go b/flag_impl.go index 9f96fbce85..87d4044fbf 100644 --- a/flag_impl.go +++ b/flag_impl.go @@ -29,7 +29,13 @@ type fnValue struct { func (f fnValue) Get() any { return f.v.Get() } func (f fnValue) Set(s string) error { return f.fn(s) } -func (f fnValue) String() string { return f.v.String() } +func (f fnValue) String() string { + if f.v == nil { + return "" + } + return f.v.String() +} + func (f fnValue) Serialize() string { if s, ok := f.v.(Serializer); ok { return s.Serialize()