From 415487dfc9bd96af1a24acff553755fb66899243 Mon Sep 17 00:00:00 2001 From: Jorge Bucaran Date: Wed, 17 Feb 2016 13:53:24 +0900 Subject: [PATCH] Teach uninstall handler about uninstall options. + Now __fisher_plugin_uninstall_handler is aware of a third argument, `option` that can be used to indicate the event handler or uninstall file abot any options available in `fisher uninstall`, namely, --force. + In addition, the uninstaller mechanism no longer receives the name of the plugin, as this information is usually already available to plugins anyway. + Finally, a path to the parent directory where the uninstall.fish file is located is given instead of the full path to the file. Again, the plugin usually knows the name of the file, `uninstall.fish`. --- functions/__fisher_plugin_uninstall_handler.fish | 9 ++++++--- test/plugin-uninstall-handler.fish | 13 +++++++++---- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/functions/__fisher_plugin_uninstall_handler.fish b/functions/__fisher_plugin_uninstall_handler.fish index d37caba..7dc6820 100644 --- a/functions/__fisher_plugin_uninstall_handler.fish +++ b/functions/__fisher_plugin_uninstall_handler.fish @@ -1,5 +1,8 @@ -function __fisher_plugin_uninstall_handler -a plugin file - if source $file $plugin $file - emit uninstall_$plugin $file +function __fisher_plugin_uninstall_handler -a plugin file option + set -l path (dirname $file) + + if source $file $path "$option" + emit uninstall_$plugin $path "$option" + functions -e uninstall_$plugin end end diff --git a/test/plugin-uninstall-handler.fish b/test/plugin-uninstall-handler.fish index 6104826..f7cadfb 100644 --- a/test/plugin-uninstall-handler.fish +++ b/test/plugin-uninstall-handler.fish @@ -1,4 +1,5 @@ set -l path $DIRNAME/.t-$TESTNAME-(random) +set -l option "--foobar" function -S setup mkdir -p $path @@ -15,10 +16,14 @@ function -S teardown functions -e emit end -test "$TESTNAME - Evaluate uninstaller with plugin name and path as arguments" - (__fisher_plugin_uninstall_handler foo $path/uninstall.fish | sed -n 1p) = "source foo $path/uninstall.fish" +test "$TESTNAME - Evaluate uninstaller with path and \$option as arguments" + "source $path $option" = ( + __fisher_plugin_uninstall_handler foo $path/uninstall.fish $option | sed -n 1p + ) end -test "$TESTNAME - Emit uninstall_ events with path as argument" - (__fisher_plugin_uninstall_handler foo $path/uninstall.fish | sed -n 2p) = "emit uninstall_foo $path/uninstall.fish" +test "$TESTNAME - Emit uninstall_ events with path and \$option as argument" + "emit uninstall_foo $path $option" = ( + __fisher_plugin_uninstall_handler foo $path/uninstall.fish $option | sed -n 2p + ) end