Skip to content

Commit d7f6384

Browse files
authored
Updated the zsh completions to escape the command name for a custom completion. (#364)
1 parent e146504 commit d7f6384

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

Sources/ArgumentParser/Completions/ZshCompletionsGenerator.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ extension ArgumentDefinition {
185185

186186
case .custom:
187187
// Generate a call back into the command to retrieve a completions list
188-
let commandName = commands.first!._commandName
188+
let commandName = commands.first!._commandName.zshEscapingCommandName()
189189
return "{_custom_completion $_\(commandName)_commandname \(customCompletionCall(commands)) $words}"
190190
}
191191
}

Tests/ArgumentParserUnitTests/CompletionScriptTests.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,9 @@ extension CompletionScriptTests {
127127
struct EscapedCommand: ParsableCommand {
128128
@Option(help: #"Escaped chars: '[]\."#)
129129
var one: String
130+
131+
@Argument(completion: .custom { _ in ["d", "e", "f"] })
132+
var two: String
130133
}
131134

132135
func testEscaped_Zsh() throws {
@@ -222,6 +225,7 @@ _escaped-command() {
222225
local -a args
223226
args+=(
224227
'--one[Escaped chars: '"'"'\\[\\]\\\\.]:one:'
228+
':two:{_custom_completion $_escaped_command_commandname ---completion -- two $words}'
225229
'(-h --help)'{-h,--help}'[Show help information.]'
226230
)
227231
_arguments -w -s -S $args[@] && ret=0

0 commit comments

Comments
 (0)