2019-11-27 01:24:29 -07:00
|
|
|
# -*- sh -*-
|
2022-04-25 05:45:19 -07:00
|
|
|
# shellcheck source=lib/functions/plugins.bash
|
|
|
|
. "$(dirname "$(dirname "$0")")/lib/functions/plugins.bash"
|
2019-11-27 01:24:29 -07:00
|
|
|
|
2020-08-28 16:09:22 -07:00
|
|
|
# shellcheck disable=SC2059
|
2017-08-18 21:56:28 -07:00
|
|
|
plugin_current_command() {
|
2016-07-24 08:47:17 -07:00
|
|
|
local plugin_name=$1
|
2020-08-28 16:09:22 -07:00
|
|
|
local terminal_format=$2
|
2016-07-24 08:47:17 -07:00
|
|
|
|
2017-09-04 10:04:56 -07:00
|
|
|
check_if_plugin_exists "$plugin_name"
|
2016-07-24 08:47:17 -07:00
|
|
|
|
2017-09-04 10:04:56 -07:00
|
|
|
local search_path
|
2022-12-27 06:33:59 -07:00
|
|
|
search_path=$PWD
|
2017-09-04 10:04:56 -07:00
|
|
|
local version_and_path
|
2019-10-22 16:03:05 -07:00
|
|
|
version_and_path=$(find_versions "$plugin_name" "$search_path")
|
2018-11-10 04:32:02 -07:00
|
|
|
local full_version
|
|
|
|
full_version=$(cut -d '|' -f 1 <<<"$version_and_path")
|
2017-09-04 10:04:56 -07:00
|
|
|
local version_file_path
|
|
|
|
version_file_path=$(cut -d '|' -f 2 <<<"$version_and_path")
|
2020-08-28 16:09:22 -07:00
|
|
|
local version_not_installed
|
|
|
|
local description=""
|
2016-08-27 21:43:54 -07:00
|
|
|
|
2018-11-10 04:32:02 -07:00
|
|
|
IFS=' ' read -r -a versions <<<"$full_version"
|
2018-12-20 15:25:30 -07:00
|
|
|
for version in "${versions[@]}"; do
|
2020-08-28 16:09:22 -07:00
|
|
|
if ! (check_if_version_exists "$plugin_name" "$version"); then
|
|
|
|
version_not_installed="$version"
|
|
|
|
fi
|
2018-11-10 04:32:02 -07:00
|
|
|
done
|
2017-09-04 10:04:56 -07:00
|
|
|
check_for_deprecated_plugin "$plugin_name"
|
2016-07-30 17:35:37 -07:00
|
|
|
|
2020-08-28 16:09:22 -07:00
|
|
|
if [ -n "$version_not_installed" ]; then
|
|
|
|
description="Not installed. Run \"asdf install $plugin $version\""
|
|
|
|
printf "$terminal_format" "$plugin" "$version" "$description" 1>&2
|
|
|
|
return 1
|
|
|
|
elif [ -z "$full_version" ]; then
|
2021-11-13 20:35:42 -07:00
|
|
|
description="No version is set. Run \"asdf <global|shell|local> $plugin <version>\""
|
2020-08-28 16:09:22 -07:00
|
|
|
printf "$terminal_format" "$plugin" "______" "$description" 1>&2
|
|
|
|
return 126
|
2016-07-24 08:47:17 -07:00
|
|
|
else
|
2020-08-28 16:09:22 -07:00
|
|
|
description="$version_file_path"
|
|
|
|
printf "$terminal_format" "$plugin" "$full_version" "$description"
|
2016-07-24 08:47:17 -07:00
|
|
|
fi
|
|
|
|
}
|
2016-07-30 17:35:37 -07:00
|
|
|
|
2020-08-28 16:09:22 -07:00
|
|
|
# shellcheck disable=SC2059
|
2017-08-18 21:56:28 -07:00
|
|
|
current_command() {
|
2022-12-23 02:53:22 -07:00
|
|
|
local terminal_format="%-15s %-15s %-10s\n"
|
2020-08-28 16:09:22 -07:00
|
|
|
local exit_status=0
|
2022-04-14 08:10:17 -07:00
|
|
|
local plugin
|
2020-08-28 16:09:22 -07:00
|
|
|
|
2022-07-05 06:40:33 -07:00
|
|
|
# printf "$terminal_format" "PLUGIN" "VERSION" "SET BY CONFIG" # disable this until we release headings across the board
|
2017-08-18 21:56:28 -07:00
|
|
|
if [ $# -eq 0 ]; then
|
2022-04-25 05:45:19 -07:00
|
|
|
# shellcheck disable=SC2119
|
|
|
|
for plugin in $(plugin_list_command); do
|
2020-08-28 16:09:22 -07:00
|
|
|
plugin_current_command "$plugin" "$terminal_format"
|
2017-08-18 21:56:28 -07:00
|
|
|
done
|
|
|
|
else
|
2022-04-14 08:10:17 -07:00
|
|
|
plugin=$1
|
2020-08-28 16:09:22 -07:00
|
|
|
plugin_current_command "$plugin" "$terminal_format"
|
|
|
|
exit_status="$?"
|
2017-08-18 21:56:28 -07:00
|
|
|
fi
|
2020-08-28 16:09:22 -07:00
|
|
|
|
|
|
|
exit "$exit_status"
|
2017-08-18 21:56:28 -07:00
|
|
|
}
|
|
|
|
|
2016-07-30 17:35:37 -07:00
|
|
|
# Warn if the plugin isn't using the updated legacy file api.
|
|
|
|
check_for_deprecated_plugin() {
|
|
|
|
local plugin_name=$1
|
|
|
|
|
2017-09-04 10:04:56 -07:00
|
|
|
local plugin_path
|
|
|
|
plugin_path=$(get_plugin_path "$plugin_name")
|
|
|
|
local legacy_config
|
|
|
|
legacy_config=$(get_asdf_config_value "legacy_version_file")
|
2016-07-30 17:35:37 -07:00
|
|
|
local deprecated_script="${plugin_path}/bin/get-version-from-legacy-file"
|
|
|
|
local new_script="${plugin_path}/bin/list-legacy-filenames"
|
|
|
|
|
2017-09-04 10:04:56 -07:00
|
|
|
if [ "$legacy_config" = "yes" ] && [ -f "$deprecated_script" ] && [ ! -f "$new_script" ]; then
|
2022-12-23 02:53:22 -07:00
|
|
|
printf "Heads up! It looks like your %s plugin is out of date. You can update it with:\n\n" "$plugin_name"
|
|
|
|
printf " asdf plugin-update %s\n\n" "$plugin_name"
|
2016-07-30 17:35:37 -07:00
|
|
|
fi
|
|
|
|
}
|
2019-11-27 01:24:29 -07:00
|
|
|
|
|
|
|
current_command "$@"
|