Skip to content
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

proposal: when installing or using a linked... #1166

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
38 changes: 25 additions & 13 deletions src/main/bash/sdkman-install.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env bash

#
# Copyright 2021 Marco Vermeulen
# Copyright 2021-2023 Marco Vermeulen
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand All @@ -16,6 +16,26 @@
# limitations under the License.
#


function __sdk_set_default() {
local candidate VERSION

candidate="$1"
VERSION="$2"

if [[ "$sdkman_auto_answer" != 'true' && "$auto_answer_upgrade" != 'true' && -n "$CURRENT" ]]; then
__sdkman_echo_confirm "Do you want ${candidate} version ${VERSION} to be set as default? (Y/n): "
read USE
fi

if [[ -z "$USE" || "$USE" == "y" || "$USE" == "Y" ]]; then
echo ""
__sdkman_echo_green "Setting ${candidate} version ${VERSION} as default."
__sdkman_link_candidate_version "$candidate" "$VERSION"
__sdkman_add_to_path "$candidate"
fi
}

function __sdk_install() {
local candidate version folder

Expand All @@ -36,17 +56,7 @@ function __sdk_install() {
__sdkman_determine_current_version "$candidate"
__sdkman_install_candidate_version "$candidate" "$VERSION" || return 1

if [[ "$sdkman_auto_answer" != 'true' && "$auto_answer_upgrade" != 'true' && -n "$CURRENT" ]]; then
__sdkman_echo_confirm "Do you want ${candidate} ${VERSION} to be set as default? (Y/n): "
read USE
fi

if [[ -z "$USE" || "$USE" == "y" || "$USE" == "Y" ]]; then
echo ""
__sdkman_echo_green "Setting ${candidate} ${VERSION} as default."
__sdkman_link_candidate_version "$candidate" "$VERSION"
__sdkman_add_to_path "$candidate"
fi
__sdk_set_default "$candidate" "$VERSION"

return 0
elif [[ "$VERSION_VALID" == 'invalid' && -n "$folder" ]]; then
Expand Down Expand Up @@ -104,7 +114,9 @@ function __sdkman_install_local_version() {
if [[ -d "$folder" ]]; then
__sdkman_echo_green "Linking ${candidate} ${version} to ${folder}"
ln -s "$folder" "${SDKMAN_CANDIDATES_DIR}/${candidate}/${version}"
__sdkman_echo_green "Done installing!"

__sdk_set_default "${candidate}" "${version}"
__sdkman_echo_green "Done linking to $folder!"
else
__sdkman_echo_red "Invalid path! Refusing to link ${candidate} ${version} to ${folder}."
return 1
Expand Down
7 changes: 2 additions & 5 deletions src/main/bash/sdkman-use.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env bash

#
# Copyright 2021 Marco Vermeulen
# Copyright 2021-2023 Marco Vermeulen
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -49,10 +49,7 @@ function __sdk_use() {
export PATH=${PATH//${SDKMAN_CANDIDATES_DIR}\/${candidate}\/${matched_version}/${SDKMAN_CANDIDATES_DIR}\/${candidate}\/${version}}
fi

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"
fi
__sdk_set_default "$candidate" "$version"

echo ""
__sdkman_echo_green "Using ${candidate} version ${version} in this shell."
Expand Down