From c9aca4900c7ed3ef21b7b668f40848082dd24a3a Mon Sep 17 00:00:00 2001 From: Trevor Brown Date: Tue, 13 Jul 2021 17:25:29 -0400 Subject: [PATCH] feat: Allow callback scripts to be implemented in any language The original code invoked all plugin callback scripts with Bash. While all plugin callback scripts are currently implemented in Bash it is conceivable that another a better shell language will emerge and become popular. I dont think mandating Bash is the right choice anymore. I do think that for nearly all plugins Bash is the right choice right now and for compatibility purposes Bash should be encouraged. --- lib/commands/command-help.bash | 8 ++++---- lib/commands/command-install.bash | 4 ++-- lib/commands/command-latest.bash | 2 +- lib/commands/command-list-all.bash | 2 +- lib/commands/command-plugin-add.bash | 2 +- lib/commands/command-plugin-remove.bash | 2 +- lib/commands/command-uninstall.bash | 2 +- lib/utils.bash | 6 +++--- test/fixtures/dummy_broken_plugin/bin/install | 0 test/fixtures/dummy_broken_plugin/bin/list-all | 0 test/fixtures/dummy_legacy_plugin/bin/install | 0 test/fixtures/dummy_legacy_plugin/bin/list-all | 0 .../dummy_legacy_plugin/bin/list-legacy-filenames | 0 test/fixtures/dummy_legacy_plugin/bin/parse-legacy-file | 0 test/fixtures/dummy_plugin/bin/help.overview | 0 test/fixtures/dummy_plugin/bin/install | 0 test/fixtures/dummy_plugin/bin/list-all | 0 test/fixtures/dummy_plugin/bin/list-legacy-filenames | 0 test/fixtures/dummy_plugin/bin/parse-legacy-file | 0 test/fixtures/dummy_plugin/bin/post-plugin-add | 0 test/fixtures/dummy_plugin/bin/pre-plugin-remove | 0 21 files changed, 14 insertions(+), 14 deletions(-) mode change 100644 => 100755 test/fixtures/dummy_broken_plugin/bin/install mode change 100644 => 100755 test/fixtures/dummy_broken_plugin/bin/list-all mode change 100644 => 100755 test/fixtures/dummy_legacy_plugin/bin/install mode change 100644 => 100755 test/fixtures/dummy_legacy_plugin/bin/list-all mode change 100644 => 100755 test/fixtures/dummy_legacy_plugin/bin/list-legacy-filenames mode change 100644 => 100755 test/fixtures/dummy_legacy_plugin/bin/parse-legacy-file mode change 100644 => 100755 test/fixtures/dummy_plugin/bin/help.overview mode change 100644 => 100755 test/fixtures/dummy_plugin/bin/install mode change 100644 => 100755 test/fixtures/dummy_plugin/bin/list-all mode change 100644 => 100755 test/fixtures/dummy_plugin/bin/list-legacy-filenames mode change 100644 => 100755 test/fixtures/dummy_plugin/bin/parse-legacy-file mode change 100644 => 100755 test/fixtures/dummy_plugin/bin/post-plugin-add mode change 100644 => 100755 test/fixtures/dummy_plugin/bin/pre-plugin-remove diff --git a/lib/commands/command-help.bash b/lib/commands/command-help.bash index cce311713..00d96a575 100644 --- a/lib/commands/command-help.bash +++ b/lib/commands/command-help.bash @@ -94,18 +94,18 @@ print_plugin_help() { # Eventually @jthegedus or someone else will format the output from these # scripts in a certain way. - bash "${plugin_path}"/bin/help.overview + "${plugin_path}"/bin/help.overview if [ -f "${plugin_path}"/bin/help.deps ]; then - bash "${plugin_path}"/bin/help.deps + "${plugin_path}"/bin/help.deps fi if [ -f "${plugin_path}"/bin/help.config ]; then - bash "${plugin_path}"/bin/help.config + "${plugin_path}"/bin/help.config fi if [ -f "${plugin_path}"/bin/help.links ]; then - bash "${plugin_path}"/bin/help.links + "${plugin_path}"/bin/help.links fi } diff --git a/lib/commands/command-install.bash b/lib/commands/command-install.bash index 89163419c..a8c769f0a 100644 --- a/lib/commands/command-install.bash +++ b/lib/commands/command-install.bash @@ -169,7 +169,7 @@ install_tool_version() { export ASDF_DOWNLOAD_PATH=$download_path mkdir "$download_path" asdf_run_hook "pre_asdf_download_${plugin_name}" "$full_version" - bash "${plugin_path}"/bin/download + "${plugin_path}"/bin/download ) fi @@ -188,7 +188,7 @@ install_tool_version() { export ASDF_CONCURRENCY=$concurrency mkdir "$install_path" asdf_run_hook "pre_asdf_install_${plugin_name}" "$full_version" - bash "${plugin_path}"/bin/install + "${plugin_path}"/bin/install ) fi diff --git a/lib/commands/command-latest.bash b/lib/commands/command-latest.bash index f08cdcc47..940261840 100644 --- a/lib/commands/command-latest.bash +++ b/lib/commands/command-latest.bash @@ -15,7 +15,7 @@ latest_command() { local versions if [ -f "${plugin_path}/bin/latest-stable" ]; then - versions=$(bash "${plugin_path}"/bin/latest-stable "$query") + versions=$("${plugin_path}"/bin/latest-stable "$query") if [ -z "${versions}" ]; then # this branch requires this print to mimic the error from the list-all branch printf "No compatible versions available (%s %s)\n" "$plugin_name" "$query" >&2 diff --git a/lib/commands/command-list-all.bash b/lib/commands/command-list-all.bash index e3e23d185..f0357a367 100644 --- a/lib/commands/command-list-all.bash +++ b/lib/commands/command-list-all.bash @@ -13,7 +13,7 @@ list_all_command() { # Capture return code to allow error handling std_out_file="$(mktemp "/tmp/asdf-command-list-all-${plugin_name}.stdout.XXXXXX")" std_err_file="$(mktemp "/tmp/asdf-command-list-all-${plugin_name}.stderr.XXXXXX")" - return_code=0 && bash "${plugin_path}/bin/list-all" >"$std_out_file" 2>"$std_err_file" || return_code=$? + return_code=0 && "${plugin_path}/bin/list-all" >"$std_out_file" 2>"$std_err_file" || return_code=$? if [[ $return_code -ne 0 ]]; then # Printing all output to allow plugin to handle error formatting diff --git a/lib/commands/command-plugin-add.bash b/lib/commands/command-plugin-add.bash index 09b05e56c..afc1caf78 100644 --- a/lib/commands/command-plugin-add.bash +++ b/lib/commands/command-plugin-add.bash @@ -41,7 +41,7 @@ plugin_add_command() { ( export ASDF_PLUGIN_SOURCE_URL=$source_url export ASDF_PLUGIN_PATH=$plugin_path - bash "${plugin_path}/bin/post-plugin-add" + "${plugin_path}/bin/post-plugin-add" ) fi diff --git a/lib/commands/command-plugin-remove.bash b/lib/commands/command-plugin-remove.bash index 90df543fa..e4cee0532 100644 --- a/lib/commands/command-plugin-remove.bash +++ b/lib/commands/command-plugin-remove.bash @@ -13,7 +13,7 @@ plugin_remove_command() { if [ -f "${plugin_path}/bin/pre-plugin-remove" ]; then ( export ASDF_PLUGIN_PATH=$plugin_path - bash "${plugin_path}/bin/pre-plugin-remove" + "${plugin_path}/bin/pre-plugin-remove" ) fi diff --git a/lib/commands/command-uninstall.bash b/lib/commands/command-uninstall.bash index 37ae44ddd..2e1774f9b 100644 --- a/lib/commands/command-uninstall.bash +++ b/lib/commands/command-uninstall.bash @@ -36,7 +36,7 @@ uninstall_command() { export ASDF_INSTALL_TYPE=$install_type export ASDF_INSTALL_VERSION=$version export ASDF_INSTALL_PATH=$install_path - bash "${plugin_path}/bin/uninstall" + "${plugin_path}/bin/uninstall" ) else rm -rf "$install_path" diff --git a/lib/utils.bash b/lib/utils.bash index 721f9da9f..ce6aa0b96 100644 --- a/lib/utils.bash +++ b/lib/utils.bash @@ -198,7 +198,7 @@ find_versions() { local legacy_filenames="" if [ "$legacy_config" = "yes" ] && [ -f "$legacy_list_filenames_script" ]; then - legacy_filenames=$(bash "$legacy_list_filenames_script") + legacy_filenames=$($legacy_list_filenames_script) fi while [ "$search_path" != "/" ]; do @@ -329,7 +329,7 @@ parse_legacy_version_file() { if [ -f "$file_path" ]; then if [ -f "$parse_legacy_script" ]; then - bash "$parse_legacy_script" "$file_path" + "$parse_legacy_script" "$file_path" else cat "$file_path" fi @@ -481,7 +481,7 @@ list_plugin_bin_paths() { export ASDF_INSTALL_TYPE=$install_type export ASDF_INSTALL_VERSION=$version export ASDF_INSTALL_PATH=$install_path - bash "${plugin_path}/bin/list-bin-paths" + "${plugin_path}/bin/list-bin-paths" ) else local space_separated_list_of_bin_paths="bin" diff --git a/test/fixtures/dummy_broken_plugin/bin/install b/test/fixtures/dummy_broken_plugin/bin/install old mode 100644 new mode 100755 diff --git a/test/fixtures/dummy_broken_plugin/bin/list-all b/test/fixtures/dummy_broken_plugin/bin/list-all old mode 100644 new mode 100755 diff --git a/test/fixtures/dummy_legacy_plugin/bin/install b/test/fixtures/dummy_legacy_plugin/bin/install old mode 100644 new mode 100755 diff --git a/test/fixtures/dummy_legacy_plugin/bin/list-all b/test/fixtures/dummy_legacy_plugin/bin/list-all old mode 100644 new mode 100755 diff --git a/test/fixtures/dummy_legacy_plugin/bin/list-legacy-filenames b/test/fixtures/dummy_legacy_plugin/bin/list-legacy-filenames old mode 100644 new mode 100755 diff --git a/test/fixtures/dummy_legacy_plugin/bin/parse-legacy-file b/test/fixtures/dummy_legacy_plugin/bin/parse-legacy-file old mode 100644 new mode 100755 diff --git a/test/fixtures/dummy_plugin/bin/help.overview b/test/fixtures/dummy_plugin/bin/help.overview old mode 100644 new mode 100755 diff --git a/test/fixtures/dummy_plugin/bin/install b/test/fixtures/dummy_plugin/bin/install old mode 100644 new mode 100755 diff --git a/test/fixtures/dummy_plugin/bin/list-all b/test/fixtures/dummy_plugin/bin/list-all old mode 100644 new mode 100755 diff --git a/test/fixtures/dummy_plugin/bin/list-legacy-filenames b/test/fixtures/dummy_plugin/bin/list-legacy-filenames old mode 100644 new mode 100755 diff --git a/test/fixtures/dummy_plugin/bin/parse-legacy-file b/test/fixtures/dummy_plugin/bin/parse-legacy-file old mode 100644 new mode 100755 diff --git a/test/fixtures/dummy_plugin/bin/post-plugin-add b/test/fixtures/dummy_plugin/bin/post-plugin-add old mode 100644 new mode 100755 diff --git a/test/fixtures/dummy_plugin/bin/pre-plugin-remove b/test/fixtures/dummy_plugin/bin/pre-plugin-remove old mode 100644 new mode 100755