diff --git a/CHANGELOG.md b/CHANGELOG.md index 37f22fd1..01040d0b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,7 +4,7 @@ Features -* Add support for custom `plugin-add` and `plugin-remove` in plugins (#670) +* Add support for `post-plugin-add` and `pre-plugin-remove` in plugins (#670) * Add configurable command hooks for plugin installation and removal (#670) ```shell diff --git a/docs/plugins-create.md b/docs/plugins-create.md index f9d88a83..58bd8953 100644 --- a/docs/plugins-create.md +++ b/docs/plugins-create.md @@ -88,7 +88,7 @@ Note: This will only apply for users who have enabled the `legacy_version_file` This can be used to further parse the legacy file found by asdf. If `parse-legacy-file` isn't implemented, asdf will simply cat the file to determine the version. The script will be passed the file path as its first argument. -#### bin/plugin-add +#### bin/post-plugin-add This can be used to run any post-installation actions after the plugin has been added to asdf. @@ -101,7 +101,7 @@ See also the related hooks: * `post_asdf_plugin_add` * `post_asdf_plugin_add_${plugin_name}` -#### bin/plugin-remove +#### bin/pre-plugin-remove This can be used to run any pre-removal actions before the plugin will be removed from asdf. diff --git a/lib/commands/command-plugin-add.bash b/lib/commands/command-plugin-add.bash index 77a2e989..09b05e56 100644 --- a/lib/commands/command-plugin-add.bash +++ b/lib/commands/command-plugin-add.bash @@ -37,11 +37,11 @@ plugin_add_command() { exit 1 fi - if [ -f "${plugin_path}/bin/plugin-add" ]; then + if [ -f "${plugin_path}/bin/post-plugin-add" ]; then ( export ASDF_PLUGIN_SOURCE_URL=$source_url export ASDF_PLUGIN_PATH=$plugin_path - bash "${plugin_path}/bin/plugin-add" + bash "${plugin_path}/bin/post-plugin-add" ) fi diff --git a/lib/commands/command-plugin-remove.bash b/lib/commands/command-plugin-remove.bash index 6e243033..cd0c6a47 100644 --- a/lib/commands/command-plugin-remove.bash +++ b/lib/commands/command-plugin-remove.bash @@ -10,10 +10,10 @@ plugin_remove_command() { asdf_run_hook "pre_asdf_plugin_remove" "$plugin_name" asdf_run_hook "pre_asdf_plugin_remove_${plugin_name}" - if [ -f "${plugin_path}/bin/plugin-remove" ]; then + if [ -f "${plugin_path}/bin/pre-plugin-remove" ]; then ( export ASDF_PLUGIN_PATH=$plugin_path - bash "${plugin_path}/bin/plugin-remove" + bash "${plugin_path}/bin/pre-plugin-remove" ) fi diff --git a/test/fixtures/dummy_plugin/bin/plugin-add b/test/fixtures/dummy_plugin/bin/post-plugin-add similarity index 100% rename from test/fixtures/dummy_plugin/bin/plugin-add rename to test/fixtures/dummy_plugin/bin/post-plugin-add diff --git a/test/fixtures/dummy_plugin/bin/plugin-remove b/test/fixtures/dummy_plugin/bin/pre-plugin-remove similarity index 100% rename from test/fixtures/dummy_plugin/bin/plugin-remove rename to test/fixtures/dummy_plugin/bin/pre-plugin-remove diff --git a/test/plugin_add_command.bats b/test/plugin_add_command.bats index 5bea42fe..5de65f16 100644 --- a/test/plugin_add_command.bats +++ b/test/plugin_add_command.bats @@ -36,6 +36,14 @@ teardown() { echo "$output" | grep "plugin does-not-exist not found in repository" } +@test "plugin_add command executes post-plugin-add script" { + install_mock_plugin_repo "dummy" + + run asdf plugin-add "dummy" "${BASE_DIR}/repo-dummy" + + [ "$output" = "plugin-add path=${ASDF_DIR}/plugins/dummy source_url=${BASE_DIR}/repo-dummy" ] +} + @test "plugin_add command executes configured pre hook (generic)" { install_mock_plugin_repo "dummy" diff --git a/test/remove_command.bats b/test/remove_command.bats index 5d3e30f9..a5ac5e14 100644 --- a/test/remove_command.bats +++ b/test/remove_command.bats @@ -52,7 +52,6 @@ teardown() { [ ! -f $ASDF_DIR/shims/dummy ] } - @test "plugin_remove_command should not remove unrelated shims" { install_dummy_plugin run asdf install dummy 1.0 @@ -67,6 +66,14 @@ teardown() { [ -f $ASDF_DIR/shims/gummy ] } +@test "plugin_remove_command executes pre-plugin-remove script" { + install_dummy_plugin + + run asdf plugin-remove dummy + + [ "$output" = "plugin-remove ${ASDF_DIR}/plugins/dummy" ] +} + @test "plugin_remove_command executes configured pre hook (generic)" { install_dummy_plugin