Skip to content

Commit

Permalink
refactor - deduplicate code
Browse files Browse the repository at this point in the history
  • Loading branch information
fistach committed Apr 24, 2024
1 parent 3e8fa1c commit d6d9d88
Show file tree
Hide file tree
Showing 23 changed files with 16 additions and 1,422 deletions.
39 changes: 16 additions & 23 deletions src/main/bash/sdkman-use.sh
Original file line number Diff line number Diff line change
Expand Up @@ -42,17 +42,7 @@ function __sdk_use() {
elif [[ ${count} -eq 1 ]]
then
version=$(basename $(ls -d "${SDKMAN_CANDIDATES_DIR}/${candidate}/${major_version}"*))
if [[ $PATH =~ ${SDKMAN_CANDIDATES_DIR}/${candidate}/([^/]+) ]]; then
local matched_version

if [[ "$zsh_shell" == "true" ]]; then
matched_version=${match[1]}
else
matched_version=${BASH_REMATCH[1]}
fi

export PATH=${PATH//${SDKMAN_CANDIDATES_DIR}\/${candidate}\/${matched_version}/${SDKMAN_CANDIDATES_DIR}\/${candidate}\/${version}}
fi
__sdkman_change_candidate_in_path "$candidate"
__sdkman_echo_green "Using ${candidate} version ${version} in this shell."
else
echo ""
Expand All @@ -74,18 +64,7 @@ function __sdk_use() {
# Just update the *_HOME and PATH for this shell.
__sdkman_set_candidate_home "$candidate" "$version"

if [[ $PATH =~ ${SDKMAN_CANDIDATES_DIR}/${candidate}/([^/]+) ]]; then
local matched_version

if [[ "$zsh_shell" == "true" ]]; then
matched_version=${match[1]}
else
matched_version=${BASH_REMATCH[1]}
fi

export PATH=${PATH//${SDKMAN_CANDIDATES_DIR}\/${candidate}\/${matched_version}/${SDKMAN_CANDIDATES_DIR}\/${candidate}\/${version}}
fi

__sdkman_change_candidate_in_path "$candidate"
if [[ ! (-L "${SDKMAN_CANDIDATES_DIR}/${candidate}/current" || -d "${SDKMAN_CANDIDATES_DIR}/${candidate}/current") ]]; then
__sdkman_echo_green "Setting ${candidate} version ${version} as default."
__sdkman_link_candidate_version "$candidate" "$version"
Expand All @@ -95,3 +74,17 @@ function __sdk_use() {
__sdkman_echo_green "Using ${candidate} version ${version} in this shell."
fi
}

function __sdkman_change_candidate_in_path() {
if [[ $PATH =~ ${SDKMAN_CANDIDATES_DIR}/${1}/([^/]+) ]]; then
local matched_version

if [[ "$zsh_shell" == "true" ]]; then
matched_version=${match[1]}
else
matched_version=${BASH_REMATCH[1]}
fi

export PATH=${PATH//${SDKMAN_CANDIDATES_DIR}\/${candidate}\/${matched_version}/${SDKMAN_CANDIDATES_DIR}\/${candidate}\/${version}}
fi
}
82 changes: 0 additions & 82 deletions src/test/resources/features/checksum_verification.feature

This file was deleted.

24 changes: 0 additions & 24 deletions src/test/resources/features/command_line_interop.feature

This file was deleted.

39 changes: 0 additions & 39 deletions src/test/resources/features/current_candidate.feature

This file was deleted.

35 changes: 0 additions & 35 deletions src/test/resources/features/default_version.feature

This file was deleted.

33 changes: 0 additions & 33 deletions src/test/resources/features/flush.feature

This file was deleted.

45 changes: 0 additions & 45 deletions src/test/resources/features/home.feature

This file was deleted.

25 changes: 0 additions & 25 deletions src/test/resources/features/hooks.feature

This file was deleted.

Loading

0 comments on commit d6d9d88

Please sign in to comment.