Revert "Refactor fishAddFileFlag for better flexibility [#1156]"

This reverts commit fcce511478c1aabd0e4a6af313acd74a89aaa21c.
This commit is contained in:
Erin Call 2020-10-22 14:22:01 -07:00
parent c3263d495e
commit 5c8d915be7
No known key found for this signature in database
GPG Key ID: 4071FF6C15B8DAD1

24
fish.go
View File

@ -4,7 +4,6 @@ import (
"bytes" "bytes"
"fmt" "fmt"
"io" "io"
"reflect"
"strings" "strings"
"text/template" "text/template"
) )
@ -159,17 +158,24 @@ func (a *App) prepareFishFlags(flags []Flag, previousCommands []string) []string
} }
func fishAddFileFlag(flag Flag, completion *strings.Builder) { func fishAddFileFlag(flag Flag, completion *strings.Builder) {
val := reflect.ValueOf(flag) switch f := flag.(type) {
// if flag is a non-nil pointer to a struct... case *GenericFlag:
if val.Kind() != reflect.Invalid && val.Elem().Kind() == reflect.Struct { if f.TakesFile {
field := val.Elem().FieldByName("TakesFile") return
// if flag's underlying type has a bool field called TakesFile, whose value is true... }
if field.Kind() == reflect.Bool && field.Bool() { case *StringFlag:
// don't append '-f' if f.TakesFile {
return
}
case *StringSliceFlag:
if f.TakesFile {
return
}
case *PathFlag:
if f.TakesFile {
return return
} }
} }
// append '-f', indicating that arguments to this flag are *not* meant to be file paths
completion.WriteString(" -f") completion.WriteString(" -f")
} }