From 1cfb1fc3fc1716b03f92201fd009e9fabbd0b1c9 Mon Sep 17 00:00:00 2001 From: Michael Hobbs Date: Sat, 7 Feb 2015 14:09:39 -0800 Subject: [PATCH] implement dokku shell and ls (by @plietar). refs #312 --- plugins/00_dokku-standard/commands | 15 ++++++++ plugins/common/functions | 36 ++++++++++++++++++ plugins/shell/commands | 59 ++++++++++++++++++++++++++++++ plugins/shell/inputrc | 1 + tests.mk | 2 +- 5 files changed, 112 insertions(+), 1 deletion(-) create mode 100755 plugins/shell/commands create mode 100644 plugins/shell/inputrc diff --git a/plugins/00_dokku-standard/commands b/plugins/00_dokku-standard/commands index 00003535f..3052233e8 100755 --- a/plugins/00_dokku-standard/commands +++ b/plugins/00_dokku-standard/commands @@ -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< [-t] Show the last logs for an application (-t follows) run Run a command in the environment of an application url Show the first URL for an application (compatibility) diff --git a/plugins/common/functions b/plugins/common/functions index 121eeddaa..08a0bb4f6 100644 --- a/plugins/common/functions +++ b/plugins/common/functions @@ -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 " $@" } diff --git a/plugins/shell/commands b/plugins/shell/commands new file mode 100755 index 000000000..c6dca6ffe --- /dev/null +++ b/plugins/shell/commands @@ -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<