Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ struct ZshCompletionsGenerator {
return """
#compdef \(type._commandName)
local context state state_descr line
_\(type._commandName)_commandname=$words[1]
_\(type._commandName.zshEscapingCommandName())_commandname=$words[1]
typeset -A opt_args

\(generateCompletionFunction([type]))
Expand Down Expand Up @@ -122,6 +122,10 @@ extension String {
fileprivate func zshEscaped() -> String {
self.zshEscapingSingleQuotes().zshEscapingMetacharacters()
}

fileprivate func zshEscapingCommandName() -> String {
self.replacingOccurrences(of: "-", with: "_")
}
}

extension ArgumentDefinition {
Expand Down
12 changes: 6 additions & 6 deletions Tests/ArgumentParserUnitTests/CompletionScriptTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -125,13 +125,13 @@ extension CompletionScriptTests {
}

extension CompletionScriptTests {
struct Escaped: ParsableCommand {
struct EscapedCommand: ParsableCommand {
@Option(help: #"Escaped chars: '[]\."#)
var one: String
}

func testEscaped_Zsh() throws {
XCTAssertEqual(zshEscapedCompletion, Escaped.completionScript(for: .zsh))
XCTAssertEqual(zshEscapedCompletion, EscapedCommand.completionScript(for: .zsh))
}
}

Expand Down Expand Up @@ -213,12 +213,12 @@ complete -F _base base
"""

private let zshEscapedCompletion = """
#compdef escaped
#compdef escaped-command
local context state state_descr line
_escaped_commandname=$words[1]
_escaped_command_commandname=$words[1]
typeset -A opt_args

_escaped() {
_escaped-command() {
integer ret=1
local -a args
args+=(
Expand All @@ -236,7 +236,7 @@ _custom_completion() {
_describe '' completions
}

_escaped
_escaped-command
"""

private let fishBaseCompletions = """
Expand Down