From fe09b44734aaf438786718e60204883267b25632 Mon Sep 17 00:00:00 2001 From: huiyifyj Date: Wed, 21 May 2025 09:30:54 +0800 Subject: [PATCH] optimize: use self properties instead of declared new variables Reduce declared variables and use self properties directly in `TakesValue` and `GetDefaultText` methods. --- flag_impl.go | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/flag_impl.go b/flag_impl.go index 2495b6efac..bceec3fce0 100644 --- a/flag_impl.go +++ b/flag_impl.go @@ -247,8 +247,7 @@ func (f *FlagBase[T, C, V]) GetEnvVars() []string { // TakesValue returns true if the flag takes a value, otherwise false func (f *FlagBase[T, C, V]) TakesValue() bool { - var t T - return reflect.TypeOf(t) == nil || reflect.TypeOf(t).Kind() != reflect.Bool + return reflect.TypeOf(f.Value) == nil || reflect.TypeOf(f.Value).Kind() != reflect.Bool } // GetDefaultText returns the default text for this flag @@ -256,8 +255,7 @@ func (f *FlagBase[T, C, V]) GetDefaultText() string { if f.DefaultText != "" { return f.DefaultText } - var v V - return v.ToString(f.Value) + return f.creator.ToString(f.Value) } // RunAction executes flag action if set