asdf

Форк
0
/
command-current.bash 
83 строки · 2.6 Кб
1
# -*- sh -*-
2
# shellcheck source=lib/functions/plugins.bash
3
. "$(dirname "$(dirname "$0")")/lib/functions/plugins.bash"
4

5
# shellcheck disable=SC2059
6
plugin_current_command() {
7
  local plugin_name=$1
8
  local terminal_format=$2
9

10
  check_if_plugin_exists "$plugin_name"
11

12
  local search_path
13
  search_path=$PWD
14
  local version_and_path
15
  version_and_path=$(find_versions "$plugin_name" "$search_path")
16
  local full_version
17
  full_version=$(cut -d '|' -f 1 <<<"$version_and_path")
18
  local version_file_path
19
  version_file_path=$(cut -d '|' -f 2 <<<"$version_and_path")
20
  local version_not_installed
21
  local description=""
22

23
  IFS=' ' read -r -a versions <<<"$full_version"
24
  for version in "${versions[@]}"; do
25
    if ! (check_if_version_exists "$plugin_name" "$version"); then
26
      version_not_installed="$version"
27
    fi
28
  done
29
  check_for_deprecated_plugin "$plugin_name"
30

31
  if [ -n "$version_not_installed" ]; then
32
    description="Not installed. Run \"asdf install $plugin $version\""
33
    printf "$terminal_format" "$plugin" "$version" "$description" 1>&2
34
    return 1
35
  elif [ -z "$full_version" ]; then
36
    description="No version is set. Run \"asdf <global|shell|local> $plugin <version>\""
37
    printf "$terminal_format" "$plugin" "______" "$description" 1>&2
38
    return 126
39
  else
40
    description="$version_file_path"
41
    printf "$terminal_format" "$plugin" "$full_version" "$description"
42
  fi
43
}
44

45
# shellcheck disable=SC2059
46
current_command() {
47
  local terminal_format="%-15s %-15s %-10s\n"
48
  local exit_status=0
49
  local plugin
50

51
  # printf "$terminal_format" "PLUGIN" "VERSION" "SET BY CONFIG" # disable this until we release headings across the board
52
  if [ $# -eq 0 ]; then
53
    # shellcheck disable=SC2119
54
    for plugin in $(plugin_list_command); do
55
      plugin_current_command "$plugin" "$terminal_format"
56
    done
57
  else
58
    plugin=$1
59
    plugin_current_command "$plugin" "$terminal_format"
60
    exit_status="$?"
61
  fi
62

63
  exit "$exit_status"
64
}
65

66
# Warn if the plugin isn't using the updated legacy file api.
67
check_for_deprecated_plugin() {
68
  local plugin_name=$1
69

70
  local plugin_path
71
  plugin_path=$(get_plugin_path "$plugin_name")
72
  local legacy_config
73
  legacy_config=$(get_asdf_config_value "legacy_version_file")
74
  local deprecated_script="${plugin_path}/bin/get-version-from-legacy-file"
75
  local new_script="${plugin_path}/bin/list-legacy-filenames"
76

77
  if [ "$legacy_config" = "yes" ] && [ -f "$deprecated_script" ] && [ ! -f "$new_script" ]; then
78
    printf "Heads up! It looks like your %s plugin is out of date. You can update it with:\n\n" "$plugin_name"
79
    printf "  asdf plugin-update %s\n\n" "$plugin_name"
80
  fi
81
}
82

83
current_command "$@"
84

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.