Files
dokku/plugins/shell/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

62 lines
1.0 KiB
Bash
Executable File

#!/usr/bin/env bash
[[ " shell help shell:help " == *" $1 "* ]] || exit $DOKKU_NOT_IMPLEMENTED_EXIT
set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x
case "$1" in
shell)
INPUTRC="$PLUGIN_ROOT/inputrc"
HISTFILE=~/.dokku_history
history -r || true
trim()
{
sed -e 's/^[[:space:]]*//g' -e 's/[[:space:]]*$//g'
}
trap 'history -w' EXIT
while true; do
trap '' SIGINT
read -ep "dokku> " line || {
echo; true; break
}
trap - SIGINT
line=$(echo $line | trim)
CMD=$(echo $line | awk '{ print $1 }')
[[ -z $CMD ]] && continue
[[ "$line" != "$(fc -ln -1 | trim)" ]] && history -s "$line"
case $CMD in
# shell builtins
clear)
clear
;;
quit|exit)
break
;;
# Not a built-in, run as regular dokku command
*)
dokku $line || true
esac
done
;;
help | shell:help)
cat<<EOF
shell, Spawn dokku shell
EOF
;;
*)
exit $DOKKU_NOT_IMPLEMENTED_EXIT
;;
esac