diff --git a/CHANGELOG.md b/CHANGELOG.md index 7e3a7cb3..b594ad2d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,7 +6,9 @@ Add new items at the end of the relevant section under **Unreleased**. ## [Unreleased] -*No new changes.* +### Fixes + +- Bash completion scripts correctly handles subcommands with hyphens. ([#780]) --- diff --git a/Sources/ArgumentParser/Completions/BashCompletionsGenerator.swift b/Sources/ArgumentParser/Completions/BashCompletionsGenerator.swift index 216884f7..630e7326 100644 --- a/Sources/ArgumentParser/Completions/BashCompletionsGenerator.swift +++ b/Sources/ArgumentParser/Completions/BashCompletionsGenerator.swift @@ -290,7 +290,7 @@ extension [ParsableCommand.Type] { case "${subcommand}" in \(subcommands.map { $0._commandName }.joined(separator: "|"))) # Offer subcommand argument completions - "\(functionName)_${subcommand}" + "\(functionName)_${subcommand//-/_}" ;; *) # Offer subcommand completions diff --git a/Tests/ArgumentParserExampleTests/Snapshots/testMathBashCompletionScript().bash b/Tests/ArgumentParserExampleTests/Snapshots/testMathBashCompletionScript().bash index 130f0933..64e7eb9c 100644 --- a/Tests/ArgumentParserExampleTests/Snapshots/testMathBashCompletionScript().bash +++ b/Tests/ArgumentParserExampleTests/Snapshots/testMathBashCompletionScript().bash @@ -169,7 +169,7 @@ _math() { case "${subcommand}" in add|multiply|stats|help) # Offer subcommand argument completions - "_math_${subcommand}" + "_math_${subcommand//-/_}" ;; *) # Offer subcommand completions @@ -202,7 +202,7 @@ _math_stats() { case "${subcommand}" in average|stdev|quantiles) # Offer subcommand argument completions - "_math_stats_${subcommand}" + "_math_stats_${subcommand//-/_}" ;; *) # Offer subcommand completions diff --git a/Tests/ArgumentParserUnitTests/Snapshots/testBase_Bash().bash b/Tests/ArgumentParserUnitTests/Snapshots/testBase_Bash().bash index 32d67dc9..421c6ac5 100644 --- a/Tests/ArgumentParserUnitTests/Snapshots/testBase_Bash().bash +++ b/Tests/ArgumentParserUnitTests/Snapshots/testBase_Bash().bash @@ -214,7 +214,7 @@ _base_test() { case "${subcommand}" in sub-command|escaped-command|help) # Offer subcommand argument completions - "_base_test_${subcommand}" + "_base_test_${subcommand//-/_}" ;; *) # Offer subcommand completions