From 9420ca1aec2f28cae89a0aef3bf366485870c972 Mon Sep 17 00:00:00 2001 From: Victor Hugo Borja Date: Sat, 19 Jan 2019 13:48:21 -0600 Subject: [PATCH] Add hooks for plugin uninstall --- CHANGELOG.md | 3 +++ lib/commands/uninstall.sh | 3 +++ test/uninstall_command.bats | 21 +++++++++++++++++++++ 3 files changed, 27 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 15beffb7..1d361400 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,9 @@ Features pre_foo_bar = echo about to execute command bar from foo with args: ${@} post_foo_bar = echo just executed command bar from foo with args: ${@} + + pre_asdf_uninstall_foo = echo will remove foo version ${1} + post_asdf_uninstall_foo = echo removed foo version ${1} ``` * New shim version meta-data allows shims to not depend on a particular plugin nor on its relative executable path (#431) diff --git a/lib/commands/uninstall.sh b/lib/commands/uninstall.sh index 8a8928e3..fe698f45 100644 --- a/lib/commands/uninstall.sh +++ b/lib/commands/uninstall.sh @@ -23,6 +23,7 @@ uninstall_command() { exit 1 fi + asdf_run_hook "pre_asdf_uninstall_${plugin_name}" "$full_version" remove_shims_for_version "$plugin_name" "$full_version" if [ -f "${plugin_path}/bin/uninstall" ]; then @@ -35,4 +36,6 @@ uninstall_command() { else rm -rf "$install_path" fi + + asdf_run_hook "post_asdf_uninstall_${plugin_name}" "$full_version" } diff --git a/test/uninstall_command.bats b/test/uninstall_command.bats index 5465aaf6..109a3341 100644 --- a/test/uninstall_command.bats +++ b/test/uninstall_command.bats @@ -86,3 +86,24 @@ teardown() { run uninstall_command dummy 1.0 [ -f $ASDF_DIR/shims/gummy ] } + +@test "uninstall command executes configured pre hook" { + cat > $HOME/.asdfrc <<-'EOM' +pre_asdf_uninstall_dummy = echo will uninstall dummy $1 +EOM + + run install_command dummy 1.0 + run uninstall_command dummy 1.0 + [ "$output" == "will uninstall dummy 1.0" ] +} + +@test "uninstall command executes configured post hook" { + cat > $HOME/.asdfrc <<-'EOM' +post_asdf_uninstall_dummy = echo removed dummy $1 +EOM + + run install_command dummy 1.0 + run uninstall_command dummy 1.0 + echo $output + [ "$output" == "removed dummy 1.0" ] +}