From e17c93181f6b66d8dae96d29330039504c03674f Mon Sep 17 00:00:00 2001 From: Dmitry Kutakov Date: Mon, 30 Dec 2019 19:41:39 +0100 Subject: [PATCH 1/2] fix ineffectual assignments Warnings are produced by "ineffassign" linter --- altsrc/json_source_context.go | 30 +++++++++++++++--------------- altsrc/map_input_source_test.go | 2 +- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/altsrc/json_source_context.go b/altsrc/json_source_context.go index d52957f2c2..7d70a2a57a 100644 --- a/altsrc/json_source_context.go +++ b/altsrc/json_source_context.go @@ -79,9 +79,9 @@ func (x *jsonSource) Duration(name string) (time.Duration, error) { if err != nil { return 0, err } - v, ok := (time.Duration)(0), false - if v, ok = i.(time.Duration); !ok { - return v, fmt.Errorf("unexpected type %T for %q", i, name) + v, ok := i.(time.Duration) + if !ok { + return 0, fmt.Errorf("unexpected type %T for %q", i, name) } return v, nil } @@ -91,9 +91,9 @@ func (x *jsonSource) Float64(name string) (float64, error) { if err != nil { return 0, err } - v, ok := (float64)(0), false - if v, ok = i.(float64); !ok { - return v, fmt.Errorf("unexpected type %T for %q", i, name) + v, ok := i.(float64) + if !ok { + return 0, fmt.Errorf("unexpected type %T for %q", i, name) } return v, nil } @@ -103,9 +103,9 @@ func (x *jsonSource) String(name string) (string, error) { if err != nil { return "", err } - v, ok := "", false - if v, ok = i.(string); !ok { - return v, fmt.Errorf("unexpected type %T for %q", i, name) + v, ok := i.(string) + if !ok { + return "", fmt.Errorf("unexpected type %T for %q", i, name) } return v, nil } @@ -161,9 +161,9 @@ func (x *jsonSource) Generic(name string) (cli.Generic, error) { if err != nil { return nil, err } - v, ok := (cli.Generic)(nil), false - if v, ok = i.(cli.Generic); !ok { - return v, fmt.Errorf("unexpected type %T for %q", i, name) + v, ok := i.(cli.Generic) + if !ok { + return nil, fmt.Errorf("unexpected type %T for %q", i, name) } return v, nil } @@ -173,9 +173,9 @@ func (x *jsonSource) Bool(name string) (bool, error) { if err != nil { return false, err } - v, ok := false, false - if v, ok = i.(bool); !ok { - return v, fmt.Errorf("unexpected type %T for %q", i, name) + v, ok := i.(bool) + if !ok { + return false, fmt.Errorf("unexpected type %T for %q", i, name) } return v, nil } diff --git a/altsrc/map_input_source_test.go b/altsrc/map_input_source_test.go index a921d0493a..5046d1485d 100644 --- a/altsrc/map_input_source_test.go +++ b/altsrc/map_input_source_test.go @@ -20,6 +20,6 @@ func TestMapDuration(t *testing.T) { d, err = inputSource.Duration("duration_of_string_type") expect(t, time.Minute, d) expect(t, nil, err) - d, err = inputSource.Duration("duration_of_int_type") + _, err = inputSource.Duration("duration_of_int_type") refute(t, nil, err) } From 5998e27dd71340af37a525ece0fcd28cf79f094b Mon Sep 17 00:00:00 2001 From: Dmitry Kutakov Date: Tue, 31 Dec 2019 16:36:01 +0100 Subject: [PATCH 2/2] remove unused code --- app.go | 11 ----------- context.go | 1 - helpers_test.go | 6 ------ 3 files changed, 18 deletions(-) diff --git a/app.go b/app.go index c04e9afdaf..dd8f1deb39 100644 --- a/app.go +++ b/app.go @@ -7,7 +7,6 @@ import ( "io" "os" "path/filepath" - "reflect" "sort" "time" ) @@ -485,16 +484,6 @@ func (a *App) VisibleFlags() []Flag { return visibleFlags(a.Flags) } -func (a *App) hasFlag(flag Flag) bool { - for _, f := range a.Flags { - if reflect.DeepEqual(flag, f) { - return true - } - } - - return false -} - func (a *App) errWriter() io.Writer { // When the app ErrWriter is nil use the package level one. if a.ErrWriter == nil { diff --git a/context.go b/context.go index c0c526f411..74ed51912e 100644 --- a/context.go +++ b/context.go @@ -17,7 +17,6 @@ type Context struct { App *App Command *Command shellComplete bool - setFlags map[string]bool flagSet *flag.FlagSet parentContext *Context } diff --git a/helpers_test.go b/helpers_test.go index 767f404e9d..9217e89e8e 100644 --- a/helpers_test.go +++ b/helpers_test.go @@ -24,9 +24,3 @@ func expect(t *testing.T, a interface{}, b interface{}) { t.Errorf("(%s:%d) Expected %v (type %v) - Got %v (type %v)", fn, line, b, reflect.TypeOf(b), a, reflect.TypeOf(a)) } } - -func refute(t *testing.T, a interface{}, b interface{}) { - if reflect.DeepEqual(a, b) { - t.Errorf("Did not expect %v (type %v) - Got %v (type %v)", b, reflect.TypeOf(b), a, reflect.TypeOf(a)) - } -}