From dcc3727cabf84228d7b5389d57ab887c9bcec065 Mon Sep 17 00:00:00 2001 From: Victor Hugo Borja Date: Sat, 19 Jan 2019 13:16:13 -0600 Subject: [PATCH] Add pre-install and pre-reshim hooks --- CHANGELOG.md | 3 +++ lib/commands/install.sh | 1 + lib/commands/reshim.sh | 2 ++ test/install_command.bats | 11 ++++++++++- test/reshim_command.bats | 11 +++++++++++ 5 files changed, 27 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d5228c81..15beffb7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,7 +9,10 @@ Features The following hooks will be executed when set: ```shell + pre_asdf_install_foo = echo will install foo version ${1} post_asdf_install_foo = echo installed foo version ${1} + + pre_asdf_reshim_foo = echo will reshim foo version ${1} post_asdf_reshim_foo = echo reshimmed foo version ${1} pre_foo_bar = echo about to execute command bar from foo with args: ${@} diff --git a/lib/commands/install.sh b/lib/commands/install.sh index 6d81bfa2..cff6137d 100644 --- a/lib/commands/install.sh +++ b/lib/commands/install.sh @@ -96,6 +96,7 @@ install_tool_version() { export ASDF_INSTALL_PATH=$install_path export ASDF_CONCURRENCY=$concurrency mkdir "$install_path" + asdf_run_hook "pre_asdf_install_${plugin_name}" "$full_version" bash "${plugin_path}"/bin/install ) diff --git a/lib/commands/reshim.sh b/lib/commands/reshim.sh index cdd233be..11803945 100644 --- a/lib/commands/reshim.sh +++ b/lib/commands/reshim.sh @@ -20,6 +20,7 @@ reshim_command() { 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 @@ -30,6 +31,7 @@ reshim_command() { 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" diff --git a/test/install_command.bats b/test/install_command.bats index 1b7253b3..3a44cd97 100644 --- a/test/install_command.bats +++ b/test/install_command.bats @@ -139,9 +139,18 @@ teardown() { [ ! -f $ASDF_DIR/installs/dummy/system/version ] } +@test "install command executes configured pre plugin install hook" { + cat > $HOME/.asdfrc <<-'EOM' +pre_asdf_install_dummy = echo will install dummy $1 +EOM + + run install_command dummy 1.0 + [ "$output" == "will install dummy 1.0" ] +} + @test "install command executes configured post plugin install hook" { cat > $HOME/.asdfrc <<-'EOM' -post_asdf_install_dummy = eval echo HEY $version FROM $plugin_name +post_asdf_install_dummy = echo HEY $version FROM $plugin_name EOM run install_command dummy 1.0 diff --git a/test/reshim_command.bats b/test/reshim_command.bats index 054b8e9b..0d8e9c5d 100644 --- a/test/reshim_command.bats +++ b/test/reshim_command.bats @@ -99,6 +99,17 @@ teardown() { [ "1" -eq "$(ls $ASDF_DIR/shims/dummy* | wc -l)" ] } +@test "reshim command executes configured pre hook" { + run install_command dummy 1.0 + + cat > $HOME/.asdfrc <<-'EOM' +pre_asdf_reshim_dummy = echo RESHIM +EOM + + run reshim_command dummy 1.0 + [ "$output" == "RESHIM" ] +} + @test "reshim command executes configured post hook" { run install_command dummy 1.0