From d076f87deea8053076860edba9b4a95cba8adc89 Mon Sep 17 00:00:00 2001 From: Craig Siemens Date: Wed, 20 Oct 2021 09:55:32 -0600 Subject: [PATCH] Updated the zsh completions to escape the command name for a custom completion. --- .../ArgumentParser/Completions/ZshCompletionsGenerator.swift | 2 +- Tests/ArgumentParserUnitTests/CompletionScriptTests.swift | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/Sources/ArgumentParser/Completions/ZshCompletionsGenerator.swift b/Sources/ArgumentParser/Completions/ZshCompletionsGenerator.swift index 5ebef374c..52b4489bf 100644 --- a/Sources/ArgumentParser/Completions/ZshCompletionsGenerator.swift +++ b/Sources/ArgumentParser/Completions/ZshCompletionsGenerator.swift @@ -185,7 +185,7 @@ extension ArgumentDefinition { case .custom: // Generate a call back into the command to retrieve a completions list - let commandName = commands.first!._commandName + let commandName = commands.first!._commandName.zshEscapingCommandName() return "{_custom_completion $_\(commandName)_commandname \(customCompletionCall(commands)) $words}" } } diff --git a/Tests/ArgumentParserUnitTests/CompletionScriptTests.swift b/Tests/ArgumentParserUnitTests/CompletionScriptTests.swift index 63f11fd50..727914371 100644 --- a/Tests/ArgumentParserUnitTests/CompletionScriptTests.swift +++ b/Tests/ArgumentParserUnitTests/CompletionScriptTests.swift @@ -127,6 +127,9 @@ extension CompletionScriptTests { struct EscapedCommand: ParsableCommand { @Option(help: #"Escaped chars: '[]\."#) var one: String + + @Argument(completion: .custom { _ in ["d", "e", "f"] }) + var two: String } func testEscaped_Zsh() throws { @@ -222,6 +225,7 @@ _escaped-command() { local -a args args+=( '--one[Escaped chars: '"'"'\\[\\]\\\\.]:one:' + ':two:{_custom_completion $_escaped_command_commandname ---completion -- two $words}' '(-h --help)'{-h,--help}'[Show help information.]' ) _arguments -w -s -S $args[@] && ret=0