Files
dokku/plugins/plugin/commands
Jose Diaz-Gonzalez 70511c340d Check if command is implemented in a plugin before executing plugin code
Because of how plugin commands are implemented, their output can be incredibly verbose. Rather than executing even the `set -eo pipefail` parts of a plugin, we immediately check if the command is implemented by a plugin. If it is not, then we continue on as normal.

One side-effect of this change is that plugin commands need to be duplicated again:

- once in the command array
- once for the actual body of the command
- once in the help output

This is also quite hackish, and probably not the best way to decrease trace output. Note that we drop approximately 2k lines worth of logs with this change.
2015-09-18 16:09:59 -04:00

86 lines
2.3 KiB
Bash
Executable File

#!/usr/bin/env bash
[[ " plugin plugin:install plugin:install-dependencies plugin:update plugin:disable plugin:enable plugin:uninstall help plugin:help " == *" $1 "* ]] || exit $DOKKU_NOT_IMPLEMENTED_EXIT
set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x
source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions"
source "$PLUGIN_AVAILABLE_PATH/plugin/functions"
case "$1" in
plugin)
plugn list
;;
plugin:install)
case "$2" in
--core)
[[ "$#" -gt 2 ]] && dokku_log_info1_quiet "Cannot install additional core plugins, running core plugin install trigger"
PLUGIN_PATH="$PLUGIN_CORE_PATH" plugn trigger install
;;
https:*|git:*)
PLUGIN_GIT_URL="$2"
download_and_enable_plugin $PLUGIN_GIT_URL
plugn trigger install
;;
*)
plugn trigger install
;;
esac
;;
plugin:install-dependencies)
if [[ $2 == "--core" ]]; then
export PLUGIN_PATH="$PLUGIN_CORE_PATH"
fi
plugn trigger dependencies
;;
plugin:update)
case "$2" in
https:*|git:*)
PLUGIN_GIT_URL="$2"
download_and_enable_plugin $PLUGIN_GIT_URL
plugn trigger update
;;
*)
plugn trigger update
;;
esac
;;
plugin:disable)
[[ -z $2 ]] && dokku_log_fail "Please specify a plugin to disable"
PLUGIN="$2"
disable_plugin "$PLUGIN"
;;
plugin:enable)
[[ -z $2 ]] && dokku_log_fail "Please specify a plugin to enable"
PLUGIN="$2"
enable_plugin "$PLUGIN"
;;
plugin:uninstall)
[[ -z $2 ]] && dokku_log_fail "Please specify a plugin to enable"
PLUGIN="$2"
uninstall_plugin "$PLUGIN"
;;
help | plugin:help)
cat<<EOF
plugin, Print active plugins
plugin:install [--core|git-url], Optionally download git-url & run install trigger for active plugins (or only core ones)
plugin:install-dependencies [--core], Run install-dependencies trigger for active plugins (or only core ones)
plugin:update [git-url], Optionally download git-url & run update trigger for active plugins
plugin:enable <name>, Enable a previously disabled plugin
plugin:disable <name>, Disable an installed plugin (third-party only)
plugin:uninstall <name>, Uninstall a plugin (third-party only)
EOF
;;
*)
exit $DOKKU_NOT_IMPLEMENTED_EXIT
;;
esac