implement dokku shell and ls (by @plietar). refs #312
This commit is contained in:
@@ -25,6 +25,20 @@ case "$1" in
|
||||
dokku apps:destroy $2
|
||||
;;
|
||||
|
||||
ls)
|
||||
apps=$(ls -d $DOKKU_ROOT/*/ 2>/dev/null) || (echo "You haven't depoyed any applications yet" && exit 1)
|
||||
|
||||
dokku_col_log_info2_quiet "App Name" "Container id"
|
||||
|
||||
for app in $apps; do
|
||||
if [[ -f $app/CONTAINER ]]; then
|
||||
dokku_col_log_msg "$(basename $app)" "$(< $app/CONTAINER)"
|
||||
else
|
||||
dokku_col_log_msg "$(basename $app)"
|
||||
fi
|
||||
done
|
||||
;;
|
||||
|
||||
logs)
|
||||
[[ -z $2 ]] && echo "Please specify an app to run the command on" && exit 1
|
||||
verify_app_name "$2"
|
||||
@@ -93,6 +107,7 @@ case "$1" in
|
||||
|
||||
help)
|
||||
cat && cat<<EOF
|
||||
ls Pretty listing of deployed applications and containers
|
||||
logs <app> [-t] Show the last logs for an application (-t follows)
|
||||
run <app> <cmd> Run a command in the environment of an application
|
||||
url <app> Show the first URL for an application (compatibility)
|
||||
|
||||
@@ -33,6 +33,42 @@ dokku_log_info2_quiet() {
|
||||
fi
|
||||
}
|
||||
|
||||
dokku_col_log_info1() {
|
||||
printf "%-40s %-40s\n" "-----> $@"
|
||||
}
|
||||
|
||||
dokku_col_log_info1_quiet() {
|
||||
if [[ -z "$DOKKU_QUIET_OUTPUT" ]];then
|
||||
printf "%-40s %-40s\n" "-----> $@"
|
||||
else
|
||||
return 0
|
||||
fi
|
||||
}
|
||||
|
||||
dokku_col_log_info2() {
|
||||
printf "%-40s %-40s\n" "=====> $@"
|
||||
}
|
||||
|
||||
dokku_col_log_info2_quiet() {
|
||||
if [[ -z "$DOKKU_QUIET_OUTPUT" ]];then
|
||||
printf "%-40s %-40s\n" "=====> $@"
|
||||
else
|
||||
return 0
|
||||
fi
|
||||
}
|
||||
|
||||
dokku_col_log_msg() {
|
||||
printf "%-40s %-40s\n" "$@"
|
||||
}
|
||||
|
||||
dokku_col_log_msg_quiet() {
|
||||
if [[ -z "$DOKKU_QUIET_OUTPUT" ]];then
|
||||
printf "%-40s %-40s\n" "$@"
|
||||
else
|
||||
return 0
|
||||
fi
|
||||
}
|
||||
|
||||
dokku_log_verbose() {
|
||||
echo " $@"
|
||||
}
|
||||
|
||||
59
plugins/shell/commands
Executable file
59
plugins/shell/commands
Executable file
@@ -0,0 +1,59 @@
|
||||
#!/usr/bin/env bash
|
||||
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 && cat<<EOF
|
||||
shell Spawn dokku shell
|
||||
EOF
|
||||
;;
|
||||
|
||||
*)
|
||||
exit $DOKKU_NOT_IMPLEMENTED_EXIT
|
||||
;;
|
||||
|
||||
esac
|
||||
1
plugins/shell/inputrc
Normal file
1
plugins/shell/inputrc
Normal file
@@ -0,0 +1 @@
|
||||
set disable-completion on
|
||||
2
tests.mk
2
tests.mk
@@ -57,7 +57,7 @@ lint:
|
||||
# SC2001: See if you can use ${variable//search/replace} instead. - https://github.com/koalaman/shellcheck/wiki/SC2001
|
||||
@echo linting...
|
||||
@$(QUIET) shellcheck -e SC2029 ./contrib/dokku_client.sh
|
||||
@$(QUIET) find . -not -path '*/\.*' | xargs file | egrep "shell|bash" | awk '{ print $$1 }' | sed 's/://g' | grep -v dokku_client.sh | xargs shellcheck -e SC2034,SC2086,SC2143,SC2001
|
||||
@$(QUIET) find . -not -path '*/\.*' | xargs file | egrep "shell|bash" | grep -v directory | awk '{ print $$1 }' | sed 's/://g' | grep -v dokku_client.sh | xargs shellcheck -e SC2034,SC2086,SC2143,SC2001
|
||||
|
||||
unit-tests:
|
||||
@echo running unit tests...
|
||||
|
||||
Reference in New Issue
Block a user