Skip to content

Remove extraneous space in shell custom completion calls #762

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 7, 2025
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
9 changes: 5 additions & 4 deletions Sources/ArgumentParser/Completions/CompletionsGenerator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -149,12 +149,13 @@ extension ArgumentDefinition {
/// Returns a string with the arguments for the callback to generate custom completions for
/// this argument.
func customCompletionCall(_ commands: [ParsableCommand.Type]) -> String {
let subcommandNames = commands.dropFirst().map { $0._commandName }.joined(
separator: " ")
let subcommandNames =
commands.dropFirst().map { "\($0._commandName) " }.joined()
let argumentName =
names.preferredName?.synopsisString
?? self.help.keys.first?.fullPathString ?? "---"
return "---completion \(subcommandNames) -- \(argumentName)"
?? self.help.keys.first?.fullPathString
?? "---"
return "---completion \(subcommandNames)-- \(argumentName)"
}
}

Expand Down
4 changes: 2 additions & 2 deletions Tests/ArgumentParserUnitTests/Snapshots/testBase_Bash().bash
Original file line number Diff line number Diff line change
Expand Up @@ -182,11 +182,11 @@ _base_test() {
# Offer positional completions
case "${positional_number}" in
1)
__base_test_add_completions -W "$(__base_test_custom_complete ---completion -- argument)"
__base_test_add_completions -W "$(__base_test_custom_complete ---completion -- argument)"
return
;;
2)
__base_test_add_completions -W "$(__base_test_custom_complete ---completion -- nested.nestedArgument)"
__base_test_add_completions -W "$(__base_test_custom_complete ---completion -- nested.nestedArgument)"
return
;;
esac
Expand Down
4 changes: 2 additions & 2 deletions Tests/ArgumentParserUnitTests/Snapshots/testBase_Fish().fish
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ complete -c 'base-test' -n '__base-test_should_offer_completions_for "base-test"
complete -c 'base-test' -n '__base-test_should_offer_completions_for "base-test"' -l kind-counter
complete -c 'base-test' -n '__base-test_should_offer_completions_for "base-test"' -l rep1 -rfka ''
complete -c 'base-test' -n '__base-test_should_offer_completions_for "base-test"' -s r -l rep2 -rfka ''
complete -c 'base-test' -n '__base-test_should_offer_completions_for "base-test" 1' -fka '(__base-test_custom_completion ---completion -- argument)'
complete -c 'base-test' -n '__base-test_should_offer_completions_for "base-test" 2' -fka '(__base-test_custom_completion ---completion -- nested.nestedArgument)'
complete -c 'base-test' -n '__base-test_should_offer_completions_for "base-test" 1' -fka '(__base-test_custom_completion ---completion -- argument)'
complete -c 'base-test' -n '__base-test_should_offer_completions_for "base-test" 2' -fka '(__base-test_custom_completion ---completion -- nested.nestedArgument)'
complete -c 'base-test' -n '__base-test_should_offer_completions_for "base-test"' -s h -l help -d 'Show help information.'
complete -c 'base-test' -n '__base-test_should_offer_completions_for "base-test" 3' -fa 'sub-command' -d ''
complete -c 'base-test' -n '__base-test_should_offer_completions_for "base-test" 3' -fa 'escaped-command' -d ''
Expand Down
4 changes: 2 additions & 2 deletions Tests/ArgumentParserUnitTests/Snapshots/testBase_Zsh().zsh
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ _base-test() {
'*--kind-counter'
'*--rep1:rep1:'
'*'{-r,--rep2}':rep2:'
':argument:{__base-test_custom_complete "${command_name}" ---completion -- argument "${command_line[@]}"}'
':nested-argument:{__base-test_custom_complete "${command_name}" ---completion -- nested.nestedArgument "${command_line[@]}"}'
':argument:{__base-test_custom_complete "${command_name}" ---completion -- argument "${command_line[@]}"}'
':nested-argument:{__base-test_custom_complete "${command_name}" ---completion -- nested.nestedArgument "${command_line[@]}"}'
'(-h --help)'{-h,--help}'[Show help information.]'
'(-): :->command'
'(-)*:: :->arg'
Expand Down