From b5f18cae5cd0c40cb92506a96f83ee79db54dbe8 Mon Sep 17 00:00:00 2001 From: Frizlab Date: Wed, 2 Jun 2021 00:44:37 +0200 Subject: [PATCH] Fix custom completion args for bash --- .../ArgumentParser/Completions/BashCompletionsGenerator.swift | 4 ++-- Tests/ArgumentParserExampleTests/MathExampleTests.swift | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Sources/ArgumentParser/Completions/BashCompletionsGenerator.swift b/Sources/ArgumentParser/Completions/BashCompletionsGenerator.swift index 5d03d7036..925626c2d 100644 --- a/Sources/ArgumentParser/Completions/BashCompletionsGenerator.swift +++ b/Sources/ArgumentParser/Completions/BashCompletionsGenerator.swift @@ -149,7 +149,7 @@ struct BashCompletionsGenerator { ?? arg.help.keys.first?.rawValue ?? "---" return """ - $(\(commandName) ---completion \(subcommandNames) -- \(argumentName) "$COMP_WORDS") + $(\(commandName) ---completion \(subcommandNames) -- \(argumentName) "${COMP_WORDS[@]}") """ } } @@ -207,7 +207,7 @@ extension ArgumentDefinition { case .custom: // Generate a call back into the command to retrieve a completions list let commandName = commands.first!._commandName - return #"COMPREPLY=( $(compgen -W "$(\#(commandName) \#(customCompletionCall(commands)) "$COMP_WORDS")" -- "$cur") )"# + return #"COMPREPLY=( $(compgen -W "$(\#(commandName) \#(customCompletionCall(commands)) "${COMP_WORDS[@]}")" -- "$cur") )"# } } } diff --git a/Tests/ArgumentParserExampleTests/MathExampleTests.swift b/Tests/ArgumentParserExampleTests/MathExampleTests.swift index c66288397..2f23e622b 100644 --- a/Tests/ArgumentParserExampleTests/MathExampleTests.swift +++ b/Tests/ArgumentParserExampleTests/MathExampleTests.swift @@ -325,7 +325,7 @@ _math_stats_stdev() { _math_stats_quantiles() { opts="--file --directory --shell --custom --version -h --help" opts="$opts alphabet alligator branch braggart" - opts="$opts $(math ---completion stats quantiles -- customArg "$COMP_WORDS")" + opts="$opts $(math ---completion stats quantiles -- customArg "${COMP_WORDS[@]}")" if [[ $COMP_CWORD == "$1" ]]; then COMPREPLY=( $(compgen -W "$opts" -- "$cur") ) return @@ -344,7 +344,7 @@ _math_stats_quantiles() { return ;; --custom) - COMPREPLY=( $(compgen -W "$(math ---completion stats quantiles -- --custom "$COMP_WORDS")" -- "$cur") ) + COMPREPLY=( $(compgen -W "$(math ---completion stats quantiles -- --custom "${COMP_WORDS[@]}")" -- "$cur") ) return ;; esac