From e968fe6142d121d1da11aeada21b0338b62b9b16 Mon Sep 17 00:00:00 2001 From: Victor Hugo Borja Date: Wed, 27 Nov 2019 02:24:29 -0600 Subject: [PATCH] Subcommand-aware command line interface. --- asdf.fish | 16 +- asdf.sh | 21 +- bin/asdf | 195 +++++++----------- help.txt | 16 +- lib/asdf.fish | 15 ++ lib/asdf.sh | 18 ++ lib/commands/{current.sh => command-current} | 6 +- lib/commands/{shim-env.sh => command-env} | 4 + lib/commands/{shim-exec.sh => command-exec} | 4 + lib/commands/command-export-shell-version | 38 ++++ lib/commands/command-global | 5 + lib/commands/{help.sh => command-help} | 4 + lib/commands/{install.sh => command-install} | 9 +- lib/commands/{latest.sh => command-latest} | 7 +- lib/commands/{list.sh => command-list} | 4 + .../{list-all.sh => command-list-all} | 4 + lib/commands/command-local | 33 +++ .../{plugin-add.sh => command-plugin-add} | 4 + .../{plugin-list.sh => command-plugin-list} | 4 + ...in-list-all.sh => command-plugin-list-all} | 4 + .../{plugin-push.sh => command-plugin-push} | 4 + ...plugin-remove.sh => command-plugin-remove} | 4 + .../{plugin-test.sh => command-plugin-test} | 4 + ...plugin-update.sh => command-plugin-update} | 4 + lib/commands/command-reshim | 131 ++++++++++++ ...shim_versions.sh => command-shim-versions} | 4 + .../{uninstall.sh => command-uninstall} | 15 ++ lib/commands/{update.sh => command-update} | 4 + lib/commands/command-version | 2 + lib/commands/{where.sh => command-where} | 4 + lib/commands/{which.sh => command-which} | 4 + lib/commands/plugin-extension-command.sh | 23 --- lib/commands/reshim.sh | 133 ------------ lib/commands/version_commands.sh | 68 +----- lint.sh | 2 +- test/plugin_extension_command.bats | 14 +- test/shim_versions_command.bats | 4 - test/test_helpers.bash | 1 - test/uninstall_command.bats | 4 - test/update_command.bats | 56 ++--- test/version_commands.bats | 18 +- test/where_command.bats | 2 - test/which_command.bats | 3 - 43 files changed, 470 insertions(+), 449 deletions(-) create mode 100644 lib/asdf.fish create mode 100644 lib/asdf.sh rename lib/commands/{current.sh => command-current} (95%) rename lib/commands/{shim-env.sh => command-env} (90%) rename lib/commands/{shim-exec.sh => command-exec} (94%) create mode 100644 lib/commands/command-export-shell-version create mode 100644 lib/commands/command-global rename lib/commands/{help.sh => command-help} (73%) rename lib/commands/{install.sh => command-install} (95%) rename lib/commands/{latest.sh => command-latest} (83%) rename lib/commands/{list.sh => command-list} (95%) rename lib/commands/{list-all.sh => command-list-all} (93%) create mode 100644 lib/commands/command-local rename lib/commands/{plugin-add.sh => command-plugin-add} (95%) rename lib/commands/{plugin-list.sh => command-plugin-list} (94%) rename lib/commands/{plugin-list-all.sh => command-plugin-list-all} (94%) rename lib/commands/{plugin-push.sh => command-plugin-push} (91%) rename lib/commands/{plugin-remove.sh => command-plugin-remove} (88%) rename lib/commands/{plugin-test.sh => command-plugin-test} (99%) rename lib/commands/{plugin-update.sh => command-plugin-update} (92%) create mode 100644 lib/commands/command-reshim rename lib/commands/{shim_versions.sh => command-shim-versions} (66%) rename lib/commands/{uninstall.sh => command-uninstall} (77%) rename lib/commands/{update.sh => command-update} (97%) create mode 100644 lib/commands/command-version rename lib/commands/{where.sh => command-where} (96%) rename lib/commands/{which.sh => command-which} (93%) delete mode 100644 lib/commands/plugin-extension-command.sh diff --git a/asdf.fish b/asdf.fish index 639080db..72318382 100644 --- a/asdf.fish +++ b/asdf.fish @@ -20,17 +20,5 @@ for x in $asdf_bin_dirs set PATH $x $PATH end -# Add function wrapper so we can export variables -function asdf - set command $argv[1] - set -e argv[1] - - switch "$command" - case "shell" - # eval commands that need to export variables - source (env ASDF_SHELL=fish asdf "sh-$command" $argv | psub) - case '*' - # forward other commands to asdf script - command asdf "$command" $argv - end -end +# Load the asdf wrapper function +source $ASDF_DIR/lib/asdf.fish diff --git a/asdf.sh b/asdf.sh index 802049b4..a1a83609 100644 --- a/asdf.sh +++ b/asdf.sh @@ -30,24 +30,9 @@ ASDF_USER_SHIMS="${ASDF_DATA_DIR:-$HOME/.asdf}/shims" PATH="${ASDF_BIN}:$PATH" PATH="${ASDF_USER_SHIMS}:$PATH" -# Add function wrapper so we can export variables -asdf() { - local command - command="$1" - if [ "$#" -gt 0 ]; then - shift - fi - - case "$command" in - "shell") - # eval commands that need to export variables - eval "$(asdf "sh-$command" "$@")";; - *) - # forward other commands to asdf script - command asdf "$command" "$@";; - - esac -} +# shellcheck source=lib/asdf.sh +# Load the asdf wrapper function +. "${ASDF_DIR}/lib/asdf.sh" if [ -n "$ZSH_VERSION" ]; then autoload -U bashcompinit diff --git a/bin/asdf b/bin/asdf index 58be4d5b..c7485319 100755 --- a/bin/asdf +++ b/bin/asdf @@ -3,136 +3,85 @@ # shellcheck source=lib/utils.sh source "$(dirname "$(dirname "$0")")/lib/utils.sh" -load_cmd() { - for cmd in "$@"; do - # shellcheck disable=SC1091 - source "$(dirname "$(dirname "$0")")/lib/commands/$cmd.sh" +find_cmd() { + local cmd_dir="$1" + shift + + local cmd_name + local args_offset="$#" + cmd_name="command-$(echo "${@:1:${args_offset}}" | tr ' ' '-')" + while [ ! -f "$cmd_dir/$cmd_name" ] && [ "$args_offset" -gt 0 ]; do + args_offset=$((args_offset-1)) + cmd_name="command-$(echo "${@:1:${args_offset}}" | tr ' ' '-')" done + + if [ -f "$cmd_dir/$cmd_name" ]; then + echo "$cmd_dir/$cmd_name" "$((args_offset+1))" + elif [ -f "$cmd_dir/command" ]; then + echo "$cmd_dir/command" 1 + fi } -show_help() { - load_cmd "help" - help_command +find_asdf_cmd() { + local asdf_cmd_dir + asdf_cmd_dir="$(asdf_dir)/lib/commands" + case "$1" in + ('exec' | 'current' | 'env' | 'global' | 'install' | 'latest' | 'list' | 'local' |\ + 'reshim' | 'uninstall' | 'update' | 'where' | 'which' |\ + 'export-shell-version') + echo "$asdf_cmd_dir/command-$1" 2 + ;; + + ('' | '--help' | '-h' | 'help') + echo "$asdf_cmd_dir/command-help" 2 + ;; + + ('--version' | 'version') + echo "$asdf_cmd_dir/command-version" 2 + ;; + + (*) + find_cmd "$asdf_cmd_dir" "$@" + ;; + esac } -cmd_args=("${@:2}") +find_plugin_cmd() { + local ASDF_CMD_FILE args_offset + if [ -d "$(get_plugin_path "$1")/bin" ]; then + IFS=' ' read -r ASDF_CMD_FILE args_offset <<<"$(find_cmd "$(get_plugin_path "$1")/bin" "${@:2}")" + if [ -n "$ASDF_CMD_FILE" ]; then + args_offset=$((args_offset+1)) # since the first argument is the plugin name + echo "$ASDF_CMD_FILE" "$args_offset" + fi + fi +} -case "$1" in +asdf_cmd() { + local ASDF_CMD_FILE args_offset - "exec") - load_cmd "shim-exec" - shim_exec_command "${cmd_args[@]}";; + if [ "shell" == "$1" ]; then + echo "Shell integration is not enabled. Please ensure you source asdf in your shell setup." >&2 + exit 1; + fi - "env") - load_cmd "shim-env" - shim_env_command "${cmd_args[@]}";; + IFS=' ' read -r ASDF_CMD_FILE args_offset <<<"$(find_asdf_cmd "$@")" + if [ -z "$ASDF_CMD_FILE" ]; then + IFS=' ' read -r ASDF_CMD_FILE args_offset <<<"$(find_plugin_cmd "$@")" + fi - "where") - load_cmd "where" - where_command "${cmd_args[@]}";; + if [ -x "$ASDF_CMD_FILE" ]; then + exec "$ASDF_CMD_FILE" "${@:${args_offset}}" + elif [ -f "$ASDF_CMD_FILE" ]; then + set -- "${@:${args_offset}}" + source "$ASDF_CMD_FILE" + else + local asdf_cmd_dir + asdf_cmd_dir="$(asdf_dir)/lib/commands" + echo "Unknown command: \`asdf ${*}\`" >&2 + source "$asdf_cmd_dir/command-help" >&2 + return 127 + fi +} - "which") - load_cmd "which" - which_command "${cmd_args[@]}";; - - "update") - load_cmd "update" - update_command "${cmd_args[@]}";; - - "install") - load_cmd "install" "reshim" - install_command "${cmd_args[@]}";; - - "uninstall") - load_cmd "uninstall" "reshim" - uninstall_command "${cmd_args[@]}";; - - "current") - load_cmd "current" "plugin-list" - current_command "${cmd_args[@]}";; - - "sh-shell") - load_cmd "version_commands" - shell_command "${cmd_args[@]}";; - - "shell") - echo "Shell integration is not enabled. Please ensure you source asdf in your shell setup." - exit 1;; - - "local") - load_cmd "version_commands" - local_command "${cmd_args[@]}";; - - "global") - load_cmd "version_commands" - global_command "${cmd_args[@]}";; - - "latest") - load_cmd "latest" - latest_command "${cmd_args[@]}";; - - "list") - load_cmd "list" - list_command "${cmd_args[@]}";; - - "list-all") - load_cmd "list-all" - list_all_command "${cmd_args[@]}";; - - "reshim") - load_cmd "reshim" - reshim_command "${cmd_args[@]}";; - - "plugin-add") - load_cmd "plugin-add" - plugin_add_command "${cmd_args[@]}";; - - "plugin-list") - load_cmd "plugin-list" - plugin_list_command "${cmd_args[@]}";; - - "plugin-list-all") - load_cmd "plugin-list-all" - plugin_list_all_command "${cmd_args[@]}";; - - "plugin-update") - load_cmd "plugin-update" - plugin_update_command "${cmd_args[@]}";; - - "plugin-remove") - load_cmd "plugin-remove" - plugin_remove_command "${cmd_args[@]}";; - - # Undocumented commands for development - "plugin-push") - load_cmd "plugin-push" - plugin_push_command "${cmd_args[@]}";; - - "plugin-test") - load_cmd "plugin-test" - plugin_test_command "${cmd_args[@]}";; - - "shim-versions") - load_cmd "shim_versions" - shim_versions_command "${cmd_args[@]}";; - - "--version") - asdf_version "${cmd_args[@]}";; - - "--help") - show_help;; - - "help") - show_help;; - - "") - show_help;; - - *) - load_cmd "plugin-extension-command" - plugin_extension_command "$@" # returns only on command not found - - echo "Unknown asdf command: \`${*}\`" >&2 - show_help >&2 - exit 1;; -esac +asdf_cmd "$@" diff --git a/help.txt b/help.txt index 35ab590e..414a09f4 100644 --- a/help.txt +++ b/help.txt @@ -1,12 +1,12 @@ MANAGE PLUGINS - asdf plugin-add [] Add a plugin from the plugin repo OR, add a Git repo + asdf plugin add [] Add a plugin from the plugin repo OR, add a Git repo as a plugin by specifying the name and repo url - asdf plugin-list List installed plugins - asdf plugin-list --urls List installed plugins with repository URLs - asdf plugin-list-all List plugins registered on asdf-plugins repository with URLs - asdf plugin-remove Remove plugin and package versions - asdf plugin-update Update plugin - asdf plugin-update --all Update all plugins + asdf plugin list List installed plugins + asdf plugin list --urls List installed plugins with repository URLs + asdf plugin list all List plugins registered on asdf-plugins repository with URLs + asdf plugin remove Remove plugin and package versions + asdf plugin update Update plugin + asdf plugin update --all Update all plugins MANAGE PACKAGES @@ -22,7 +22,7 @@ MANAGE PACKAGES asdf local Set the package local version asdf global Set the package global version asdf list List installed versions of a package - asdf list-all List all versions of a package + asdf list all List all versions of a package UTILS diff --git a/lib/asdf.fish b/lib/asdf.fish new file mode 100644 index 00000000..34a67886 --- /dev/null +++ b/lib/asdf.fish @@ -0,0 +1,15 @@ + +# Add function wrapper so we can export variables +function asdf + set command $argv[1] + set -e argv[1] + + switch "$command" + case "shell" + # source commands that need to export variables + source (asdf export-shell-version fish $argv | psub) + case '*' + # forward other commands to asdf script + command asdf "$command" $argv + end +end diff --git a/lib/asdf.sh b/lib/asdf.sh new file mode 100644 index 00000000..05660cfb --- /dev/null +++ b/lib/asdf.sh @@ -0,0 +1,18 @@ +# The asdf function is a wrapper so we can export variables +asdf() { + local command + command="$1" + if [ "$#" -gt 0 ]; then + shift + fi + + case "$command" in + "shell") + # commands that need to export variables + command e"val" "$(asdf export-shell-version sh "$@")";; + *) + # forward other commands to asdf script + command asdf "$command" "$@";; + + esac +} diff --git a/lib/commands/current.sh b/lib/commands/command-current similarity index 95% rename from lib/commands/current.sh rename to lib/commands/command-current index 57440af1..570b6ce2 100644 --- a/lib/commands/current.sh +++ b/lib/commands/command-current @@ -1,3 +1,5 @@ +# -*- sh -*- + plugin_current_command() { local plugin_name=$1 @@ -28,7 +30,7 @@ plugin_current_command() { current_command() { if [ $# -eq 0 ]; then - for plugin in $(plugin_list_command); do + for plugin in $(asdf plugin list); do printf "%-15s%s\\n" "$plugin" "$(plugin_current_command "$plugin")" >&2 done else @@ -55,3 +57,5 @@ check_for_deprecated_plugin() { echo "" fi } + +current_command "$@" diff --git a/lib/commands/shim-env.sh b/lib/commands/command-env similarity index 90% rename from lib/commands/shim-env.sh rename to lib/commands/command-env index 6daaf6ff..68a31323 100644 --- a/lib/commands/shim-env.sh +++ b/lib/commands/command-env @@ -1,3 +1,5 @@ +# -*- sh -*- + shim_env_command() { local shim_name="$1" local env_cmd="${2}" @@ -18,3 +20,5 @@ shim_env_command() { with_shim_executable "$shim_name" shim_env || exit $? } + +shim_env_command "$@" diff --git a/lib/commands/shim-exec.sh b/lib/commands/command-exec similarity index 94% rename from lib/commands/shim-exec.sh rename to lib/commands/command-exec index 9095dc31..216d54d2 100644 --- a/lib/commands/shim-exec.sh +++ b/lib/commands/command-exec @@ -1,3 +1,5 @@ +# -*- sh -*- + shim_exec_command() { local shim_name shim_name=$(basename "$1") @@ -28,3 +30,5 @@ shim_exec_command() { with_shim_executable "$shim_name" exec_shim || exit $? } + +shim_exec_command "$@" diff --git a/lib/commands/command-export-shell-version b/lib/commands/command-export-shell-version new file mode 100644 index 00000000..a7fef7f3 --- /dev/null +++ b/lib/commands/command-export-shell-version @@ -0,0 +1,38 @@ +# -*- sh -*- + +# Output from this command must be executable shell code +shell_command() { + local asdf_shell="$1" + shift + + if [ "$#" -lt "2" ]; then + echo "Usage: asdf shell {|--unset}" >&2 + echo 'false' + exit 1 + fi + + local plugin=$1 + local version=$2 + + local upcase_name + upcase_name=$(echo "$plugin" | tr '[:lower:]-' '[:upper:]_') + local version_env_var="ASDF_${upcase_name}_VERSION" + + if [ "$version" = "--unset" ]; then + echo "unset $version_env_var" + exit 0 + fi + if ! (check_if_version_exists "$plugin" "$version"); then + echo 'false' + exit 1 + fi + + case "$asdf_shell" in + fish ) + echo "set -gx $version_env_var \"$version\"";; + * ) + echo "export $version_env_var=\"$version\"";; + esac +} + +shell_command "$@" diff --git a/lib/commands/command-global b/lib/commands/command-global new file mode 100644 index 00000000..8e320218 --- /dev/null +++ b/lib/commands/command-global @@ -0,0 +1,5 @@ +# -*- sh -*- + +# shellcheck source=version_commands.sh +source "$(dirname "$ASDF_CMD_FILE")/version_commands.sh" +version_command global "$@" diff --git a/lib/commands/help.sh b/lib/commands/command-help similarity index 73% rename from lib/commands/help.sh rename to lib/commands/command-help index d8077e35..34d1877b 100644 --- a/lib/commands/help.sh +++ b/lib/commands/command-help @@ -1,5 +1,9 @@ +# -*- sh -*- + help_command () { echo "version: $(asdf_version)" echo "" cat "$(asdf_dir)/help.txt" } + +help_command "$@" diff --git a/lib/commands/install.sh b/lib/commands/command-install similarity index 95% rename from lib/commands/install.sh rename to lib/commands/command-install index 30527f51..7d3f578f 100644 --- a/lib/commands/install.sh +++ b/lib/commands/command-install @@ -1,3 +1,5 @@ +# -*- sh -*- + handle_failure() { local install_path="$1" rm -rf "$install_path" @@ -95,9 +97,8 @@ install_tool_version() { local install_type="version" if [ "${version_info[0]}" = "latest" ]; then - load_cmd "latest" local version - version=$(latest_command "$plugin_name" "${version_info[1]}") + version=$(asdf latest "$plugin_name" "${version_info[1]}") full_version=$version else local version="${version_info[0]}" @@ -126,10 +127,12 @@ install_tool_version() { local exit_code=$? if [ $exit_code -eq 0 ]; then - reshim_command "$plugin_name" "$full_version" + asdf reshim "$plugin_name" "$full_version" asdf_run_hook "post_asdf_install_${plugin_name}" "$full_version" else handle_failure "$install_path" fi fi } + +install_command "$@" diff --git a/lib/commands/latest.sh b/lib/commands/command-latest similarity index 83% rename from lib/commands/latest.sh rename to lib/commands/command-latest index 4dcb586a..6de752c0 100644 --- a/lib/commands/latest.sh +++ b/lib/commands/command-latest @@ -1,3 +1,5 @@ +# -*- sh -*- + latest_command() { DEFAULT_QUERY="[0-9]" @@ -7,10 +9,11 @@ latest_command() { [[ -z $query ]] && query="$DEFAULT_QUERY" # pattern from xxenv-latest (https://github.com/momo-lab/xxenv-latest) - load_cmd "list-all" - list_all_command "$plugin_name" "$query" \ + asdf list-all "$plugin_name" "$query" \ | grep -vE "(^Available versions:|-src|-dev|-latest|-stm|[-\.]rc|-alpha|-beta|[-\.]pre|-next|(a|b|c)[0-9]+|snapshot|master)" \ | sed 's/^\s\+//' \ | sort --version-sort \ | tail -1 } + +latest_command "$@" diff --git a/lib/commands/list.sh b/lib/commands/command-list similarity index 95% rename from lib/commands/list.sh rename to lib/commands/command-list index 9a009763..84b76097 100644 --- a/lib/commands/list.sh +++ b/lib/commands/command-list @@ -1,3 +1,5 @@ +# -*- sh -*- + list_command() { local plugin_name=$1 @@ -32,3 +34,5 @@ display_installed_versions() { display_error 'No versions installed' fi } + +list_command "$@" diff --git a/lib/commands/list-all.sh b/lib/commands/command-list-all similarity index 93% rename from lib/commands/list-all.sh rename to lib/commands/command-list-all index a7769038..12bbbc3c 100644 --- a/lib/commands/list-all.sh +++ b/lib/commands/command-list-all @@ -1,3 +1,5 @@ +# -*- sh -*- + list_all_command() { local plugin_name=$1 local query=$2 @@ -22,3 +24,5 @@ list_all_command() { echo "${version}" done } + +list_all_command "$@" diff --git a/lib/commands/command-local b/lib/commands/command-local new file mode 100644 index 00000000..3d3da188 --- /dev/null +++ b/lib/commands/command-local @@ -0,0 +1,33 @@ +# -*- sh -*- + +# shellcheck source=version_commands.sh +source "$(dirname "$ASDF_CMD_FILE")/version_commands.sh" + +local_command() { + local parent=false + local positional=() + + while [[ $# -gt 0 ]] + do + case $1 in + -p|--parent) + parent="true" + shift # past value + ;; + *) + positional+=("$1") # save it in an array for later + shift # past argument + ;; + esac + done + + set -- "${positional[@]}" # restore positional parameters + + if [ $parent = true ]; then + version_command local-tree "$@" + else + version_command local "$@" + fi +} + +local_command "$@" diff --git a/lib/commands/plugin-add.sh b/lib/commands/command-plugin-add similarity index 95% rename from lib/commands/plugin-add.sh rename to lib/commands/command-plugin-add index 4960a042..60d9fe09 100644 --- a/lib/commands/plugin-add.sh +++ b/lib/commands/command-plugin-add @@ -1,3 +1,5 @@ +# -*- sh -*- + plugin_add_command() { if [[ $# -lt 1 || $# -gt 2 ]]; then display_error "usage: asdf plugin-add []" @@ -33,3 +35,5 @@ plugin_add_command() { fi fi } + +plugin_add_command "$@" diff --git a/lib/commands/plugin-list.sh b/lib/commands/command-plugin-list similarity index 94% rename from lib/commands/plugin-list.sh rename to lib/commands/command-plugin-list index a8521ae4..9a9faf14 100644 --- a/lib/commands/plugin-list.sh +++ b/lib/commands/command-plugin-list @@ -1,3 +1,5 @@ +# -*- sh -*- + plugin_list_command() { local flag=$1 @@ -31,3 +33,5 @@ plugin_list_command() { fi } + +plugin_list_command "$@" diff --git a/lib/commands/plugin-list-all.sh b/lib/commands/command-plugin-list-all similarity index 94% rename from lib/commands/plugin-list-all.sh rename to lib/commands/command-plugin-list-all index 5bf97867..cf86272e 100644 --- a/lib/commands/plugin-list-all.sh +++ b/lib/commands/command-plugin-list-all @@ -1,3 +1,5 @@ +# -*- sh -*- + plugin_list_all_command() { initialize_or_update_repository @@ -21,3 +23,5 @@ plugin_list_all_command() { printf "%s%s\\n" "error: index of plugins not found at " "$plugins_index_path" fi } + +plugin_list_all_command "$@" diff --git a/lib/commands/plugin-push.sh b/lib/commands/command-plugin-push similarity index 91% rename from lib/commands/plugin-push.sh rename to lib/commands/command-plugin-push index 34ba743f..cd8a268e 100644 --- a/lib/commands/plugin-push.sh +++ b/lib/commands/command-plugin-push @@ -1,3 +1,5 @@ +# -*- sh -*- + plugin_push_command() { local plugin_name=$1 if [ "$plugin_name" = "--all" ]; then @@ -13,3 +15,5 @@ plugin_push_command() { (cd "$plugin_path" && git push) fi } + +plugin_push_command "$@" diff --git a/lib/commands/plugin-remove.sh b/lib/commands/command-plugin-remove similarity index 88% rename from lib/commands/plugin-remove.sh rename to lib/commands/command-plugin-remove index 6937472c..06e98716 100644 --- a/lib/commands/plugin-remove.sh +++ b/lib/commands/command-plugin-remove @@ -1,3 +1,5 @@ +# -*- sh -*- + plugin_remove_command() { local plugin_name=$1 check_if_plugin_exists "$plugin_name" @@ -10,3 +12,5 @@ plugin_remove_command() { grep -l "asdf-plugin: ${plugin_name}" "$(asdf_data_dir)"/shims/* 2>/dev/null | xargs rm -f } + +plugin_remove_command "$@" diff --git a/lib/commands/plugin-test.sh b/lib/commands/command-plugin-test similarity index 99% rename from lib/commands/plugin-test.sh rename to lib/commands/command-plugin-test index 319c41b7..ff8bb69f 100644 --- a/lib/commands/plugin-test.sh +++ b/lib/commands/command-plugin-test @@ -1,3 +1,5 @@ +# -*- sh -*- + plugin_test_command() { local plugin_name=$1 @@ -151,3 +153,5 @@ plugin_test_command() { rm -rf "$TEST_DIR" exit $exit_code } + +plugin_test_command "$@" diff --git a/lib/commands/plugin-update.sh b/lib/commands/command-plugin-update similarity index 92% rename from lib/commands/plugin-update.sh rename to lib/commands/command-plugin-update index 80377546..5f66427e 100644 --- a/lib/commands/plugin-update.sh +++ b/lib/commands/command-plugin-update @@ -1,3 +1,5 @@ +# -*- sh -*- + plugin_update_command() { if [ "$#" -ne 1 ]; then display_error "usage: asdf plugin-update { | --all}" @@ -18,3 +20,5 @@ plugin_update_command() { (cd "$plugin_path" && git pull) fi } + +plugin_update_command "$@" diff --git a/lib/commands/command-reshim b/lib/commands/command-reshim new file mode 100644 index 00000000..9badafcc --- /dev/null +++ b/lib/commands/command-reshim @@ -0,0 +1,131 @@ +# -*- sh -*- + +source "$(dirname "$ASDF_CMD_FILE")/reshim.sh" + +reshim_command() { + local plugin_name=$1 + local full_version=$2 + + if [ -z "$plugin_name" ]; then + local plugins_path + plugins_path=$(get_plugin_path) + + if ls "$plugins_path" &> /dev/null; then + for plugin_path in "$plugins_path"/* ; do + plugin_name=$(basename "$plugin_path") + reshim_command "$plugin_name" + done + fi + return 0 + fi + + check_if_plugin_exists "$plugin_name" + ensure_shims_dir + + if [ "$full_version" != "" ]; then + # generate for the whole package version + asdf_run_hook "pre_asdf_reshim_$plugin_name" "$full_version_name" + generate_shims_for_version "$plugin_name" "$full_version" + asdf_run_hook "post_asdf_reshim_$plugin_name" "$full_version" + else + # generate for all versions of the package + local plugin_installs_path + plugin_installs_path="$(asdf_data_dir)/installs/${plugin_name}" + + for install in "${plugin_installs_path}"/*/; do + local full_version_name + full_version_name=$(basename "$install" | sed 's/ref\-/ref\:/') + asdf_run_hook "pre_asdf_reshim_$plugin_name" "$full_version_name" + generate_shims_for_version "$plugin_name" "$full_version_name" + remove_obsolete_shims "$plugin_name" "$full_version_name" + asdf_run_hook "post_asdf_reshim_$plugin_name" "$full_version_name" + done + fi + +} + + +ensure_shims_dir() { + # Create shims dir if doesn't exist + if [ ! -d "$(asdf_data_dir)/shims" ]; then + mkdir "$(asdf_data_dir)/shims" + fi +} + + +write_shim_script() { + local plugin_name=$1 + local version=$2 + local executable_path=$3 + + if ! is_executable "$executable_path"; then + return 0 + fi + + local executable_name + executable_name=$(basename "$executable_path") + + local shim_path + shim_path="$(asdf_data_dir)/shims/$executable_name" + + if [ -f "$shim_path" ]; then + if ! grep -x "# asdf-plugin: ${plugin_name} ${version}" "$shim_path" >/dev/null; then + sed -i.bak -e "s/exec /# asdf-plugin: ${plugin_name} ${version}\\"$'\n''exec /' "$shim_path" + rm "$shim_path".bak + fi + else + cat < "$shim_path" +#!/usr/bin/env bash +# asdf-plugin: ${plugin_name} ${version} +exec $(asdf_dir)/bin/asdf exec "${executable_name}" "\$@" +EOF + fi + + chmod +x "$shim_path" +} + + +generate_shim_for_executable() { + local plugin_name=$1 + local executable=$2 + + check_if_plugin_exists "$plugin_name" + + local version + IFS=':' read -r -a version_info <<< "$full_version" + if [ "${version_info[0]}" = "ref" ]; then + version="${version_info[1]}" + else + version="${version_info[0]}" + fi + + write_shim_script "$plugin_name" "$version" "$executable" +} + +generate_shims_for_version() { + local plugin_name=$1 + local full_version=$2 + for executable_path in $(plugin_executables "$plugin_name" "$full_version"); do + write_shim_script "$plugin_name" "$full_version" "$executable_path" + done +} + +remove_obsolete_shims() { + local plugin_name=$1 + local full_version=$2 + + local shims + shims=$(plugin_shims "$plugin_name" "$full_version" | xargs -IX basename X | sort) + + local exec_names + exec_names=$(plugin_executables "$plugin_name" "$full_version" | xargs -IX basename X | sort) + + local obsolete_shims + obsolete_shims=$(comm -23 <(echo "$shims") <(echo "$exec_names")) + + for shim_name in $obsolete_shims; do + remove_shim_for_version "$plugin_name" "$full_version" "$shim_name" + done +} + +reshim_command "$@" diff --git a/lib/commands/shim_versions.sh b/lib/commands/command-shim-versions similarity index 66% rename from lib/commands/shim_versions.sh rename to lib/commands/command-shim-versions index f2cbe7ad..9a8181a1 100644 --- a/lib/commands/shim_versions.sh +++ b/lib/commands/command-shim-versions @@ -1,4 +1,8 @@ +# -*- sh -*- + shim_versions_command() { local shim_name=$1 shim_plugin_versions "$shim_name" } + +shim_versions_command "$@" diff --git a/lib/commands/uninstall.sh b/lib/commands/command-uninstall similarity index 77% rename from lib/commands/uninstall.sh rename to lib/commands/command-uninstall index fe698f45..4e5bc314 100644 --- a/lib/commands/uninstall.sh +++ b/lib/commands/command-uninstall @@ -1,3 +1,7 @@ +# -*- sh -*- + +source "$(dirname "$ASDF_CMD_FILE")/reshim.sh" + uninstall_command() { local plugin_name=$1 local full_version=$2 @@ -39,3 +43,14 @@ uninstall_command() { asdf_run_hook "post_asdf_uninstall_${plugin_name}" "$full_version" } + +remove_shims_for_version() { + local plugin_name=$1 + local full_version=$2 + for shim_path in $(plugin_shims "$plugin_name" "$full_version"); do + remove_shim_for_version "$plugin_name" "$full_version" "$shim_path" + done +} + + +uninstall_command "$@" diff --git a/lib/commands/update.sh b/lib/commands/command-update similarity index 97% rename from lib/commands/update.sh rename to lib/commands/command-update index 735da3a9..ecb724de 100644 --- a/lib/commands/update.sh +++ b/lib/commands/command-update @@ -1,3 +1,5 @@ +# -*- sh -*- + update_command() { local update_to_head=$1 @@ -46,3 +48,5 @@ sort_versions() { sed 'h; s/[+-]/./g; s/.p\([[:digit:]]\)/.z\1/; s/$/.z/; G; s/\n/ /' | \ LC_ALL=C sort -t. -k 1,1 -k 2,2n -k 3,3n -k 4,4n -k 5,5n | awk '{print $2}' } + +update_command "$@" diff --git a/lib/commands/command-version b/lib/commands/command-version new file mode 100644 index 00000000..3512457a --- /dev/null +++ b/lib/commands/command-version @@ -0,0 +1,2 @@ +# -*- sh -*- +asdf_version diff --git a/lib/commands/where.sh b/lib/commands/command-where similarity index 96% rename from lib/commands/where.sh rename to lib/commands/command-where index 3106c995..db506e6d 100644 --- a/lib/commands/where.sh +++ b/lib/commands/command-where @@ -1,3 +1,5 @@ +# -*- sh -*- + where_command() { local plugin_name=$1 local full_version=$2 @@ -41,3 +43,5 @@ where_command() { fi fi } + +where_command "$@" diff --git a/lib/commands/which.sh b/lib/commands/command-which similarity index 93% rename from lib/commands/which.sh rename to lib/commands/command-which index 5c6e251d..3a8defe8 100644 --- a/lib/commands/which.sh +++ b/lib/commands/command-which @@ -1,3 +1,5 @@ +# -*- sh -*- + which_command() { local shim_name shim_name=$(basename "$1") @@ -23,3 +25,5 @@ which_command() { with_shim_executable "$shim_name" print_exec || exit 1 } + +which_command "$@" diff --git a/lib/commands/plugin-extension-command.sh b/lib/commands/plugin-extension-command.sh deleted file mode 100644 index 19903412..00000000 --- a/lib/commands/plugin-extension-command.sh +++ /dev/null @@ -1,23 +0,0 @@ -plugin_extension_command() { - local plugin_bin_dir plugin_cmd - plugin_bin_dir="$(get_plugin_path "$1")/bin" - - if test -d "$plugin_bin_dir"; then - if test -f "$plugin_bin_dir/$2"; then - plugin_cmd="$plugin_bin_dir/$2" - shift # consume plugin name - shift # and command name - elif test -f "$plugin_bin_dir/default-command"; then - plugin_cmd="$plugin_bin_dir/default-command" - shift # only consume plugin name - fi - - if test -x "$plugin_cmd"; then - exec "$plugin_cmd" "$@" - elif test -f "$plugin_cmd"; then - # shellcheck disable=SC1090 # Cant follow non constant source - source "$plugin_cmd" - exit $? - fi - fi -} diff --git a/lib/commands/reshim.sh b/lib/commands/reshim.sh index ff656509..83b329f5 100644 --- a/lib/commands/reshim.sh +++ b/lib/commands/reshim.sh @@ -1,128 +1,3 @@ -reshim_command() { - local plugin_name=$1 - local full_version=$2 - - if [ -z "$plugin_name" ]; then - local plugins_path - plugins_path=$(get_plugin_path) - - if ls "$plugins_path" &> /dev/null; then - for plugin_path in "$plugins_path"/* ; do - plugin_name=$(basename "$plugin_path") - reshim_command "$plugin_name" - done - fi - return 0 - fi - - check_if_plugin_exists "$plugin_name" - ensure_shims_dir - - if [ "$full_version" != "" ]; then - # generate for the whole package version - asdf_run_hook "pre_asdf_reshim_$plugin_name" "$full_version_name" - generate_shims_for_version "$plugin_name" "$full_version" - asdf_run_hook "post_asdf_reshim_$plugin_name" "$full_version" - else - # generate for all versions of the package - local plugin_installs_path - plugin_installs_path="$(asdf_data_dir)/installs/${plugin_name}" - - for install in "${plugin_installs_path}"/*/; do - local full_version_name - full_version_name=$(basename "$install" | sed 's/ref\-/ref\:/') - asdf_run_hook "pre_asdf_reshim_$plugin_name" "$full_version_name" - generate_shims_for_version "$plugin_name" "$full_version_name" - remove_obsolete_shims "$plugin_name" "$full_version_name" - asdf_run_hook "post_asdf_reshim_$plugin_name" "$full_version_name" - done - fi - -} - - -ensure_shims_dir() { - # Create shims dir if doesn't exist - if [ ! -d "$(asdf_data_dir)/shims" ]; then - mkdir "$(asdf_data_dir)/shims" - fi -} - - -write_shim_script() { - local plugin_name=$1 - local version=$2 - local executable_path=$3 - - if ! is_executable "$executable_path"; then - return 0 - fi - - local executable_name - executable_name=$(basename "$executable_path") - - local shim_path - shim_path="$(asdf_data_dir)/shims/$executable_name" - - if [ -f "$shim_path" ]; then - if ! grep -x "# asdf-plugin: ${plugin_name} ${version}" "$shim_path" >/dev/null; then - sed -i.bak -e "s/exec /# asdf-plugin: ${plugin_name} ${version}\\"$'\n''exec /' "$shim_path" - rm "$shim_path".bak - fi - else - cat < "$shim_path" -#!/usr/bin/env bash -# asdf-plugin: ${plugin_name} ${version} -exec $(asdf_dir)/bin/asdf exec "${executable_name}" "\$@" -EOF - fi - - chmod +x "$shim_path" -} - - -generate_shim_for_executable() { - local plugin_name=$1 - local executable=$2 - - check_if_plugin_exists "$plugin_name" - - local version - IFS=':' read -r -a version_info <<< "$full_version" - if [ "${version_info[0]}" = "ref" ]; then - version="${version_info[1]}" - else - version="${version_info[0]}" - fi - - write_shim_script "$plugin_name" "$version" "$executable" -} - -generate_shims_for_version() { - local plugin_name=$1 - local full_version=$2 - for executable_path in $(plugin_executables "$plugin_name" "$full_version"); do - write_shim_script "$plugin_name" "$full_version" "$executable_path" - done -} - -remove_obsolete_shims() { - local plugin_name=$1 - local full_version=$2 - - local shims - shims=$(plugin_shims "$plugin_name" "$full_version" | xargs -IX basename X | sort) - - local exec_names - exec_names=$(plugin_executables "$plugin_name" "$full_version" | xargs -IX basename X | sort) - - local obsolete_shims - obsolete_shims=$(comm -23 <(echo "$shims") <(echo "$exec_names")) - - for shim_name in $obsolete_shims; do - remove_shim_for_version "$plugin_name" "$full_version" "$shim_name" - done -} remove_shim_for_version() { local plugin_name=$1 @@ -149,11 +24,3 @@ remove_shim_for_version() { rm "$shim_path" fi } - -remove_shims_for_version() { - local plugin_name=$1 - local full_version=$2 - for shim_path in $(plugin_shims "$plugin_name" "$full_version"); do - remove_shim_for_version "$plugin_name" "$full_version" "$shim_path" - done -} diff --git a/lib/commands/version_commands.sh b/lib/commands/version_commands.sh index a22c92de..3f7ad59c 100644 --- a/lib/commands/version_commands.sh +++ b/lib/commands/version_commands.sh @@ -1,3 +1,5 @@ +# -*- sh -*- + version_command() { local cmd=$1 local plugin=$2 @@ -43,69 +45,3 @@ version_command() { echo "$plugin ${versions[*]}" >> "$file" fi } - -local_command() { - local parent=false - local positional=() - - while [[ $# -gt 0 ]] - do - case $1 in - -p|--parent) - parent="true" - shift # past value - ;; - *) - positional+=("$1") # save it in an array for later - shift # past argument - ;; - esac - done - - set -- "${positional[@]}" # restore positional parameters - - if [ $parent = true ]; then - # shellcheck disable=2068 - version_command "local-tree" $@ - else - # shellcheck disable=2068 - version_command "local" $@ - fi -} - -global_command() { - # shellcheck disable=2068 - version_command "global" $@ -} - -# Output from this command must be executable shell code -shell_command() { - if [ "$#" -lt "2" ]; then - echo "Usage: asdf shell {|--unset}" >&2 - echo 'false' - exit 1 - fi - - local plugin=$1 - local version=$2 - - local upcase_name - upcase_name=$(echo "$plugin" | tr '[:lower:]-' '[:upper:]_') - local version_env_var="ASDF_${upcase_name}_VERSION" - - if [ "$version" = "--unset" ]; then - echo "unset $version_env_var" - exit 0 - fi - if ! (check_if_version_exists "$plugin" "$version"); then - echo 'false' - exit 1 - fi - - case $ASDF_SHELL in - fish ) - echo "set -gx $version_env_var \"$version\"";; - * ) - echo "export $version_env_var=\"$version\"";; - esac -} diff --git a/lint.sh b/lint.sh index c7b8a3ac..bdcac321 100755 --- a/lint.sh +++ b/lint.sh @@ -2,7 +2,7 @@ exec shellcheck -s bash -x \ asdf.sh lint.sh release/tag.sh \ bin/asdf bin/private/asdf-exec \ - lib/utils.sh lib/commands/*.sh \ + lib/utils.sh lib/commands/* \ completions/*.bash \ test/test_helpers.bash \ test/fixtures/dummy_plugin/bin/* diff --git a/test/plugin_extension_command.bats b/test/plugin_extension_command.bats index e17c7928..1e6b765b 100644 --- a/test/plugin_extension_command.bats +++ b/test/plugin_extension_command.bats @@ -15,11 +15,11 @@ teardown() { plugin_path="$(get_plugin_path dummy)" # this plugin defines a new `asdf dummy foo` command - cat <<'EOF' > "$plugin_path/bin/foo" + cat <<'EOF' > "$plugin_path/bin/command-foo" #!/usr/bin/env bash echo this is an executable $* EOF - chmod +x "$plugin_path/bin/foo" + chmod +x "$plugin_path/bin/command-foo" expected="this is an executable bar" @@ -32,7 +32,7 @@ EOF plugin_path="$(get_plugin_path dummy)" # this plugin defines a new `asdf dummy foo` command - echo 'echo sourced script has asdf utils $(get_plugin_path dummy) $*' > "$plugin_path/bin/foo" + echo 'echo sourced script has asdf utils $(get_plugin_path dummy) $*' > "$plugin_path/bin/command-foo" expected="sourced script has asdf utils $plugin_path bar" @@ -45,11 +45,11 @@ EOF plugin_path="$(get_plugin_path dummy)" # this plugin defines a new `asdf dummy` command - cat <<'EOF' > "$plugin_path/bin/default-command" + cat <<'EOF' > "$plugin_path/bin/command" #!/usr/bin/env bash echo hello EOF - chmod +x "$plugin_path/bin/default-command" + chmod +x "$plugin_path/bin/command" expected="hello" @@ -62,11 +62,11 @@ EOF plugin_path="$(get_plugin_path dummy)" # this plugin defines a new `asdf dummy` command - cat <<'EOF' > "$plugin_path/bin/default-command" + cat <<'EOF' > "$plugin_path/bin/command" #!/usr/bin/env bash echo hello $* EOF - chmod +x "$plugin_path/bin/default-command" + chmod +x "$plugin_path/bin/command" expected="hello world" diff --git a/test/shim_versions_command.bats b/test/shim_versions_command.bats index 35727c4e..97fb5c60 100644 --- a/test/shim_versions_command.bats +++ b/test/shim_versions_command.bats @@ -2,10 +2,6 @@ load test_helpers -. $(dirname $BATS_TEST_DIRNAME)/lib/commands/shim_versions.sh -. $(dirname $BATS_TEST_DIRNAME)/lib/commands/reshim.sh -. $(dirname $BATS_TEST_DIRNAME)/lib/commands/install.sh - setup() { setup_asdf_dir install_dummy_plugin diff --git a/test/test_helpers.bash b/test/test_helpers.bash index 5617b2e4..815a1504 100644 --- a/test/test_helpers.bash +++ b/test/test_helpers.bash @@ -59,4 +59,3 @@ setup_repo() { cp -r "$BATS_TEST_DIRNAME/fixtures/dummy_plugins_repo" "$ASDF_DIR/repository" touch "$(asdf_dir)/tmp/repo-updated" } - diff --git a/test/uninstall_command.bats b/test/uninstall_command.bats index ae3dfa7e..2745ba2e 100644 --- a/test/uninstall_command.bats +++ b/test/uninstall_command.bats @@ -2,10 +2,6 @@ load test_helpers -. $(dirname $BATS_TEST_DIRNAME)/lib/commands/reshim.sh -. $(dirname $BATS_TEST_DIRNAME)/lib/commands/install.sh -. $(dirname $BATS_TEST_DIRNAME)/lib/commands/uninstall.sh - setup() { setup_asdf_dir install_dummy_plugin diff --git a/test/update_command.bats b/test/update_command.bats index b2ff20cc..f10ef91e 100644 --- a/test/update_command.bats +++ b/test/update_command.bats @@ -2,17 +2,21 @@ load test_helpers -. $(dirname "$BATS_TEST_DIRNAME")/lib/commands/update.sh - setup() { - setup_asdf_dir - install_dummy_plugin + BASE_DIR=$(mktemp -dt asdf.XXXX) + HOME=$BASE_DIR/home + ASDF_DIR=$HOME/.asdf + git clone -o local "$(dirname "$BATS_TEST_DIRNAME")" "$ASDF_DIR" + git --git-dir "$ASDF_DIR/.git" remote add origin https://github.com/asdf-vm/asdf.git + mkdir -p "$ASDF_DIR/plugins" + mkdir -p "$ASDF_DIR/installs" + mkdir -p "$ASDF_DIR/shims" + mkdir -p "$ASDF_DIR/tmp" + ASDF_BIN="$ASDF_DIR/bin" - ( - cd $ASDF_DIR - git init - git remote add origin https://github.com/asdf-vm/asdf.git - ) + # shellcheck disable=SC2031 + PATH=$ASDF_BIN:$ASDF_DIR/shims:$PATH + install_dummy_plugin PROJECT_DIR=$HOME/project mkdir $PROJECT_DIR @@ -22,69 +26,69 @@ teardown() { clean_asdf_dir } -@test "update_command --head should checkout the master branch" { - run update_command --head +@test "asdf update --head should checkout the master branch" { + run asdf update --head [ "$status" -eq 0 ] cd $ASDF_DIR [ $(git rev-parse --abbrev-ref HEAD) = "master" ] } -@test "update_command should checkout the latest non-RC tag" { +@test "asdf update should checkout the latest non-RC tag" { local tag=$(git tag | grep -vi "rc" | head -1) - run update_command + run asdf update [ "$status" -eq 0 ] cd $ASDF_DIR echo $(git tag) | grep $tag [ "$status" -eq 0 ] } -@test "update_command should checkout the latest tag when configured with use_release_candidates = yes" { +@test "asdf update should checkout the latest tag when configured with use_release_candidates = yes" { local tag=$(git tag | head -1) export ASDF_CONFIG_DEFAULT_FILE=$BATS_TMPDIR/asdfrc_defaults echo "use_release_candidates = yes" > $ASDF_CONFIG_DEFAULT_FILE - run update_command + run asdf update [ "$status" -eq 0 ] cd $ASDF_DIR echo $(git tag) | grep $tag [ "$status" -eq 0 ] } -@test "update_command is a noop for non-git repos" { +@test "asdf update is a noop for non-git repos" { (cd $ASDF_DIR && rm -r .git/) - run update_command + run asdf update [ "$status" -eq 1 ] [ "$(echo -e "Update command disabled. Please use the package manager that you used to install asdf to upgrade asdf.")" == "$output" ] } -@test "update_command should not remove plugin versions" { +@test "asdf update should not remove plugin versions" { run asdf install dummy 1.1 [ "$status" -eq 0 ] [ $(cat $ASDF_DIR/installs/dummy/1.1/version) = "1.1" ] - run update_command + run asdf update [ "$status" -eq 0 ] [ -f $ASDF_DIR/installs/dummy/1.1/version ] - run update_command --head + run asdf update --head [ "$status" -eq 0 ] [ -f $ASDF_DIR/installs/dummy/1.1/version ] } -@test "update_command should not remove plugins" { +@test "asdf update should not remove plugins" { # dummy plugin is already installed - run update_command + run asdf update [ "$status" -eq 0 ] [ -d $ASDF_DIR/plugins/dummy ] - run update_command --head + run asdf update --head [ "$status" -eq 0 ] [ -d $ASDF_DIR/plugins/dummy ] } -@test "update_command should not remove shims" { +@test "asdf update should not remove shims" { run asdf install dummy 1.1 [ -f $ASDF_DIR/shims/dummy ] - run update_command + run asdf update [ "$status" -eq 0 ] [ -f $ASDF_DIR/shims/dummy ] - run update_command --head + run asdf update --head [ "$status" -eq 0 ] [ -f $ASDF_DIR/shims/dummy ] } diff --git a/test/version_commands.bats b/test/version_commands.bats index 21f80a4e..b393583b 100644 --- a/test/version_commands.bats +++ b/test/version_commands.bats @@ -2,8 +2,6 @@ load test_helpers -. $(dirname $BATS_TEST_DIRNAME)/lib/commands/version_commands.sh - setup() { setup_asdf_dir install_dummy_plugin @@ -261,26 +259,26 @@ teardown() { [ "$output" = "Shell integration is not enabled. Please ensure you source asdf in your shell setup." ] } -@test "sh-shell should emit an error when plugin does not exist" { - run asdf sh-shell "nonexistent" "1.0.0" +@test "export-shell-version should emit an error when plugin does not exist" { + run asdf export-shell-version sh "nonexistent" "1.0.0" [ "$status" -eq 1 ] [ "$output" = $'No such plugin: nonexistent\nfalse' ] } -@test "sh-shell should emit an error when version does not exist" { - run asdf sh-shell "dummy" "nonexistent" +@test "export-shell-version should emit an error when version does not exist" { + run asdf export-shell-version sh "dummy" "nonexistent" [ "$status" -eq 1 ] [ "$output" = $'version nonexistent is not installed for dummy\nfalse' ] } -@test "sh-shell should export version if it exists" { - run asdf sh-shell "dummy" "1.1.0" +@test "export-shell-version should export version if it exists" { + run asdf export-shell-version sh "dummy" "1.1.0" [ "$status" -eq 0 ] [ "$output" = "export ASDF_DUMMY_VERSION=\"1.1.0\"" ] } -@test "sh-shell should use set when shell is fish" { - ASDF_SHELL=fish run asdf sh-shell "dummy" "1.1.0" +@test "export-shell-version should use set when shell is fish" { + run asdf export-shell-version fish "dummy" "1.1.0" [ "$status" -eq 0 ] [ "$output" = "set -gx ASDF_DUMMY_VERSION \"1.1.0\"" ] } diff --git a/test/where_command.bats b/test/where_command.bats index 4573750d..22095f52 100644 --- a/test/where_command.bats +++ b/test/where_command.bats @@ -2,8 +2,6 @@ load test_helpers -. $(dirname $BATS_TEST_DIRNAME)/lib/commands/where.sh - function setup() { setup_asdf_dir install_dummy_plugin diff --git a/test/which_command.bats b/test/which_command.bats index 0dd7445c..3817fa2f 100644 --- a/test/which_command.bats +++ b/test/which_command.bats @@ -2,9 +2,6 @@ load test_helpers -. $(dirname $BATS_TEST_DIRNAME)/lib/commands/which.sh -. $(dirname $BATS_TEST_DIRNAME)/lib/commands/install.sh - setup() { setup_asdf_dir install_dummy_plugin