Skip to content

Commit

Permalink
Fix bash completion of candidates for install (sdkman#993)
Browse files Browse the repository at this point in the history
The `read` built-in uses IFS for word delimiters, and `-d` for
delimiting _where to stop reading_. We are parsing CSV, so the
combination of `IFS= -d,` results in only the first word.

Further, `read -a` fills an array variable so we don't need a loop.
  • Loading branch information
ches authored Oct 13, 2021
1 parent 1129b07 commit acd00b2
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 11 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ If the environment needs tweaking for SDKMAN to be installed, the installer will

## Running the Cucumber Features

All SDKMAN's BDD tests describing the CLI behaviour are written in Cucumber and can be found under `src/test/cucumber/sdkman`. These can be run with Gradle by running the following command:
All SDKMAN's BDD tests describing the CLI behaviour are written in Cucumber and can be found under `src/test/resources/features`. These can be run with Gradle by running the following command:

$ ./gradlew test

Expand Down
14 changes: 4 additions & 10 deletions contrib/completion/bash/sdk
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ __sdkman_complete_command() {
local -r command=$1
local -r current_word=$2

local candidates
local -a candidates

case $command in
sdk)
Expand All @@ -33,10 +33,7 @@ __sdkman_complete_command() {
;;
install|list)
local -r all_candidates=$(curl --silent "${SDKMAN_CANDIDATES_API}/candidates/all")

while IFS= read -d, -r candidate; do
candidates+=($candidate)
done <<< "$all_candidates"
IFS=',' read -r -a candidates <<< "$all_candidates"
;;
env)
candidates=("init install clear")
Expand All @@ -60,7 +57,7 @@ __sdkman_complete_candidate_version() {
local -r candidate=$2
local -r candidate_version=$3

local candidates
local -a candidates

case $command in
use|default|home|uninstall)
Expand All @@ -74,10 +71,7 @@ __sdkman_complete_candidate_version() {
;;
install)
local -r all_candidate_versions=$(curl --silent "${SDKMAN_CANDIDATES_API}/candidates/$candidate/${SDKMAN_PLATFORM}/versions/all")

while IFS= read -d, -r version; do
candidates+=($version)
done <<< "$all_candidate_versions"
IFS=',' read -r -a candidates <<< "$all_candidate_versions"
;;
esac

Expand Down

0 comments on commit acd00b2

Please sign in to comment.