Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions autocomplete/fish_autocomplete
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This is a shell completion script auto-generated by https://github.com/urfave/cli for fish.

function __%[1]_perform_completion
function __%[1]s_perform_completion
# Extract all args except the last one
set -l args (commandline -opc)
# Extract the last arg (partial input)
Expand All @@ -18,18 +18,18 @@ function __%[1]_perform_completion
end

for line in $results
if not string match -q -- "%[1]*" $line
if not string match -q -- "%[1]s*" $line
set -l parts (string split -m 1 ":" -- "$line")
if test (count $parts) -eq 2
printf "%s\t%s\n" "$parts[1]" "$parts[2]"
printf "%%s\t%%s\n" "$parts[1]" "$parts[2]"
else
printf "%s\n" "$line"
printf "%%s\n" "$line"
end
end
end
end

# Clear existing completions for %[1]
complete -c %[1] -e
# Clear existing completions for %[1]s
complete -c %[1]s -e
# Register completion function
complete -c %[1] -f -a '(__%[1]_perform_completion)'
complete -c %[1]s -f -a '(__%[1]s_perform_completion)'
30 changes: 30 additions & 0 deletions completion_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,36 @@ func TestCompletionShell(t *testing.T) {
}
}

func TestCompletionFishFormat(t *testing.T) {
// Regression test for https://github.com/urfave/cli/issues/2285
// Fish completion was broken due to incorrect format specifiers

cmd := &Command{
Name: "myapp",
EnableShellCompletion: true,
}

r := require.New(t)

// Test the fish shell completion renderer directly
fishRender := shellCompletions["fish"]
r.NotNil(fishRender, "fish completion renderer should exist")

output, err := fishRender(cmd, "myapp")
r.NoError(err)

// Verify the function name is correctly formatted
r.Contains(output, "function __myapp_perform_completion", "function name should contain app name")

// Verify no format errors (like %! or (string=) which indicate broken fmt.Sprintf)
r.NotContains(output, "%!", "output should not contain format errors")
r.NotContains(output, "(string=", "output should not contain invalid fish syntax")

// Verify the complete commands reference the app correctly
r.Contains(output, "complete -c myapp", "complete command should reference app name")
r.Contains(output, "(__myapp_perform_completion)", "completion function should be registered")
}

func TestCompletionSubcommand(t *testing.T) {
tests := []struct {
name string
Expand Down