Skip to content

Commit

Permalink
Revert "Refactor fishAddFileFlag for better flexibility [#1156]"
Browse files Browse the repository at this point in the history
This reverts commit fcce511.
  • Loading branch information
ErinCall committed Oct 22, 2020
1 parent c3263d4 commit 5c8d915
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions fish.go
Expand Up @@ -4,7 +4,6 @@ import (
"bytes"
"fmt"
"io"
"reflect"
"strings"
"text/template"
)
Expand Down Expand Up @@ -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")
}

Expand Down

0 comments on commit 5c8d915

Please sign in to comment.