From 5c8d915be7a2444901068fb08544b0b405bae178 Mon Sep 17 00:00:00 2001 From: Erin Call Date: Thu, 22 Oct 2020 14:22:01 -0700 Subject: [PATCH] Revert "Refactor fishAddFileFlag for better flexibility [#1156]" This reverts commit fcce511478c1aabd0e4a6af313acd74a89aaa21c. --- fish.go | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/fish.go b/fish.go index 474c5c7be1..588e070eab 100644 --- a/fish.go +++ b/fish.go @@ -4,7 +4,6 @@ import ( "bytes" "fmt" "io" - "reflect" "strings" "text/template" ) @@ -159,17 +158,24 @@ func (a *App) prepareFishFlags(flags []Flag, previousCommands []string) []string } func fishAddFileFlag(flag Flag, completion *strings.Builder) { - val := reflect.ValueOf(flag) - // if flag is a non-nil pointer to a struct... - if val.Kind() != reflect.Invalid && val.Elem().Kind() == reflect.Struct { - field := val.Elem().FieldByName("TakesFile") - // if flag's underlying type has a bool field called TakesFile, whose value is true... - if field.Kind() == reflect.Bool && field.Bool() { - // don't append '-f' + switch f := flag.(type) { + case *GenericFlag: + if f.TakesFile { + return + } + case *StringFlag: + if f.TakesFile { + return + } + case *StringSliceFlag: + if f.TakesFile { + return + } + case *PathFlag: + if f.TakesFile { return } } - // append '-f', indicating that arguments to this flag are *not* meant to be file paths completion.WriteString(" -f") }