Skip to content

Commit a9261cf

Browse files
authored
Merge pull request #2286 from TimSoethout/fix/fish-dynamic-completions
Fix:(issue_2285): correct function and variable naming in fish completion script
2 parents bb94d63 + 5c68aec commit a9261cf

2 files changed

Lines changed: 37 additions & 7 deletions

File tree

autocomplete/fish_autocomplete

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# This is a shell completion script auto-generated by https://github.com/urfave/cli for fish.
22

3-
function __%[1]_perform_completion
3+
function __%[1]s_perform_completion
44
# Extract all args except the last one
55
set -l args (commandline -opc)
66
# Extract the last arg (partial input)
@@ -18,18 +18,18 @@ function __%[1]_perform_completion
1818
end
1919

2020
for line in $results
21-
if not string match -q -- "%[1]*" $line
21+
if not string match -q -- "%[1]s*" $line
2222
set -l parts (string split -m 1 ":" -- "$line")
2323
if test (count $parts) -eq 2
24-
printf "%s\t%s\n" "$parts[1]" "$parts[2]"
24+
printf "%%s\t%%s\n" "$parts[1]" "$parts[2]"
2525
else
26-
printf "%s\n" "$line"
26+
printf "%%s\n" "$line"
2727
end
2828
end
2929
end
3030
end
3131

32-
# Clear existing completions for %[1]
33-
complete -c %[1] -e
32+
# Clear existing completions for %[1]s
33+
complete -c %[1]s -e
3434
# Register completion function
35-
complete -c %[1] -f -a '(__%[1]_perform_completion)'
35+
complete -c %[1]s -f -a '(__%[1]s_perform_completion)'

completion_test.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,36 @@ func TestCompletionShell(t *testing.T) {
6363
}
6464
}
6565

66+
func TestCompletionFishFormat(t *testing.T) {
67+
// Regression test for https://github.com/urfave/cli/issues/2285
68+
// Fish completion was broken due to incorrect format specifiers
69+
70+
cmd := &Command{
71+
Name: "myapp",
72+
EnableShellCompletion: true,
73+
}
74+
75+
r := require.New(t)
76+
77+
// Test the fish shell completion renderer directly
78+
fishRender := shellCompletions["fish"]
79+
r.NotNil(fishRender, "fish completion renderer should exist")
80+
81+
output, err := fishRender(cmd, "myapp")
82+
r.NoError(err)
83+
84+
// Verify the function name is correctly formatted
85+
r.Contains(output, "function __myapp_perform_completion", "function name should contain app name")
86+
87+
// Verify no format errors (like %! or (string=) which indicate broken fmt.Sprintf)
88+
r.NotContains(output, "%!", "output should not contain format errors")
89+
r.NotContains(output, "(string=", "output should not contain invalid fish syntax")
90+
91+
// Verify the complete commands reference the app correctly
92+
r.Contains(output, "complete -c myapp", "complete command should reference app name")
93+
r.Contains(output, "(__myapp_perform_completion)", "completion function should be registered")
94+
}
95+
6696
func TestCompletionSubcommand(t *testing.T) {
6797
tests := []struct {
6898
name string

0 commit comments

Comments
 (0)