Skip to content

Commit ae04cb3

Browse files
committed
Fix switch end keyword bugs in _swift_*_commands_and_positionals fish functions.
Signed-off-by: Ross Goldberg <[email protected]>
1 parent ec9f112 commit ae04cb3

File tree

3 files changed

+14
-7
lines changed

3 files changed

+14
-7
lines changed

Sources/ArgumentParser/Completions/FishCompletionsGenerator.swift

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@ extension [ParsableCommand.Type] {
1919
return """
2020
function \(commandsAndPositionalsFunctionName) -S
2121
switch $POSITIONALS[1]
22-
\(commandCases)\
23-
end
22+
\(commandCases)
2423
case '*'
2524
set COMMANDS $POSITIONALS[1]
2625
set -e POSITIONALS[1]
@@ -91,11 +90,19 @@ extension [ParsableCommand.Type] {
9190
return """
9291
case '\(last!._commandName)'
9392
\(commandsAndPositionalsFunctionName)_helper '\(
94-
subcommands.isEmpty ? "" : "-s"
93+
subcommands.isEmpty ? "" : "-s"
9594
)' '\(completableArguments.compactMap(\.optionSpec).map { "\($0)" }.joined(separator: separator))'\(
96-
subcommands.isEmpty ? "" : "\n switch $POSITIONALS[1]")
97-
\(subcommands.map { (self + [$0]).commandCases }.joined(separator: ""))
98-
""".indentingEachLine(by: 4)
95+
subcommands.isEmpty ?
96+
""
97+
: """
98+
99+
switch $POSITIONALS[1]
100+
\(subcommands.map { (self + [$0]).commandCases }.joined(separator: "\n"))
101+
end
102+
"""
103+
)
104+
"""
105+
.indentingEachLine(by: 4)
99106
}
100107

101108
private var completions: [String] {

Tests/ArgumentParserExampleTests/Snapshots/testMathFishCompletionScript().fish

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ function _swift_math_commands_and_positionals -S
1616
_swift_math_commands_and_positionals_helper '' 'version h/help'
1717
case 'quantiles'
1818
_swift_math_commands_and_positionals_helper '' 'file= directory= shell= custom= version h/help'
19+
end
1920
case 'help'
2021
_swift_math_commands_and_positionals_helper '' 'version'
2122
end

Tests/ArgumentParserUnitTests/Snapshots/testBase_Fish().fish

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ function _swift_base-test_commands_and_positionals -S
22
switch $POSITIONALS[1]
33
case 'base-test'
44
_swift_base-test_commands_and_positionals_helper '' 'name= kind= other-kind= path1= path2= path3= one two three kind-counter rep1= r/rep2= h/help'
5-
end
65
case '*'
76
set COMMANDS $POSITIONALS[1]
87
set -e POSITIONALS[1]

0 commit comments

Comments
 (0)