@@ -64,18 +64,14 @@ func (a *App) writeFishCompletionTemplate(w io.Writer) error {
64
64
})
65
65
}
66
66
67
- func (a * App ) prepareFishCommands (
68
- commands []Command ,
69
- allCommands * []string ,
70
- previousCommands []string ,
71
- ) []string {
67
+ func (a * App ) prepareFishCommands (commands []Command , allCommands * []string , previousCommands []string ) []string {
72
68
completions := []string {}
73
69
for i := range commands {
74
70
command := & commands [i ]
75
71
76
72
var completion strings.Builder
77
73
completion .WriteString (fmt .Sprintf (
78
- "complete -c %s -f -n '%s' -a '%s'" ,
74
+ "complete -r - c %s -n '%s' -a '%s'" ,
79
75
a .Name ,
80
76
a .fishSubcommandHelper (previousCommands ),
81
77
strings .Join (command .Names (), " " ),
@@ -113,24 +109,23 @@ func (a *App) prepareFishCommands(
113
109
return completions
114
110
}
115
111
116
- func (a * App ) prepareFishFlags (
117
- flags []Flag ,
118
- previousCommands []string ,
119
- ) []string {
112
+ func (a * App ) prepareFishFlags (flags []Flag , previousCommands []string ) []string {
120
113
completions := []string {}
121
114
for _ , f := range flags {
122
115
flag , ok := f .(DocGenerationFlag )
123
116
if ! ok {
124
117
continue
125
118
}
126
119
127
- var completion strings.Builder
120
+ completion := & strings.Builder {}
128
121
completion .WriteString (fmt .Sprintf (
129
- "complete -c %s -f - n '%s'" ,
122
+ "complete -c %s -n '%s'" ,
130
123
a .Name ,
131
124
a .fishSubcommandHelper (previousCommands ),
132
125
))
133
126
127
+ fishAddFileFlag (f , completion )
128
+
134
129
for idx , opt := range strings .Split (flag .GetName (), "," ) {
135
130
if idx == 0 {
136
131
completion .WriteString (fmt .Sprintf (
@@ -158,6 +153,24 @@ func (a *App) prepareFishFlags(
158
153
return completions
159
154
}
160
155
156
+ func fishAddFileFlag (flag Flag , completion * strings.Builder ) {
157
+ switch f := flag .(type ) {
158
+ case GenericFlag :
159
+ if f .TakesFile {
160
+ return
161
+ }
162
+ case StringFlag :
163
+ if f .TakesFile {
164
+ return
165
+ }
166
+ case StringSliceFlag :
167
+ if f .TakesFile {
168
+ return
169
+ }
170
+ }
171
+ completion .WriteString (" -f" )
172
+ }
173
+
161
174
func (a * App ) fishSubcommandHelper (allCommands []string ) string {
162
175
fishHelper := fmt .Sprintf ("__fish_%s_no_subcommand" , a .Name )
163
176
if len (allCommands ) > 0 {
0 commit comments