Skip to content

Commit

Permalink
[SR-7053] Fix zsh completion script (#1514)
Browse files Browse the repository at this point in the history
* [SR-7053] Fix zsh completion script by escaping [ and ]

https://bugs.swift.org/browse/SR-7053

* Revert spaces to reduce diff

* Revert unneeded changes
  • Loading branch information
mzp authored and ankitspd committed Mar 3, 2018
1 parent 92a82cb commit 9f67bee
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
2 changes: 2 additions & 0 deletions Sources/Utility/ArgumentParserShellCompletion.swift
Expand Up @@ -252,6 +252,8 @@ extension ArgumentParser {
let description = removeDefaultRegex
.replace(in: argument.usage ?? "", with: "")
.replacingOccurrences(of: "\"", with: "\\\"")
.replacingOccurrences(of: "[", with: "\\[")
.replacingOccurrences(of: "]", with: "\\]")
stream <<< "[\(description)]"

generateZshCompletion(argument, on: stream)
Expand Down
4 changes: 2 additions & 2 deletions Tests/UtilityTests/ArgumentParserTests.swift
Expand Up @@ -450,7 +450,7 @@ class ArgumentParserTests: XCTestCase {
let parser = ArgumentParser(commandName:"SomeBinary", usage: "sample parser", overview: "Sample overview")

_ = parser.add(positional: "package name of the year", kind: String.self, optional: true, usage: "The name of the package")
_ = parser.add(option: "--revision", kind: String.self, usage: "The revision")
_ = parser.add(option: "--revision", kind: String.self, usage: "The revision[Experimental]")

var output = BufferedOutputByteStream()
parser.generateCompletionScript(for: .bash, on: output)
Expand Down Expand Up @@ -494,7 +494,7 @@ class ArgumentParserTests: XCTestCase {
_SomeBinary() {
arguments=(
":The name of the package: "
"--revision[The revision]:The revision: "
"--revision[The revision\\[Experimental\\]]:The revision[Experimental]: "
)
_arguments $arguments && return
}
Expand Down

0 comments on commit 9f67bee

Please sign in to comment.