From a6b047805c3caab3ac544a79fa849b50a995e962 Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Fri, 27 Apr 2018 03:55:00 -0400 Subject: [PATCH 1/7] feat: ensure the dokku binary respects the quiet flag Previously, there were many headers being output that were unable to be removed via the --quiet flag. --- dokku | 24 ++++++++++++------------ plugins/common/functions | 7 +++++++ 2 files changed, 19 insertions(+), 12 deletions(-) diff --git a/dokku b/dokku index c0341e2c9..21c3588c0 100755 --- a/dokku +++ b/dokku @@ -191,20 +191,20 @@ case "$1" in done # New lines are blank echos for readability - echo "Usage: dokku [--quiet|--trace|--rm-container|--rm|--force] COMMAND [command-specific-options]" - echo "" - echo "Primary help options, type \"dokku COMMAND:help\" for more details, or dokku help --all to see all commands." - echo "" - echo "Commands:" - echo "" + dokku_log_quiet "Usage: dokku [--quiet|--trace|--rm-container|--rm|--force] COMMAND [command-specific-options]" + dokku_log_quiet "" + dokku_log_quiet "Primary help options, type \"dokku COMMAND:help\" for more details, or dokku help --all to see all commands." + dokku_log_quiet "" + dokku_log_quiet "Commands:" + dokku_log_quiet "" if [[ "$2" == "--all" ]] ; then for core_plugin_command in $CORE_PLUGIN_COMMANDS; do $core_plugin_command help done | sort | column -c2 -t -s, - echo "" - echo "Community plugin commands:" - echo "" + dokku_log_quiet "" + dokku_log_quiet "Community plugin commands:" + dokku_log_quiet "" for community_plugin_command in $COMMUNITY_PLUGIN_COMMANDS; do $community_plugin_command help done | sort | column -c2 -t -s, @@ -214,9 +214,9 @@ case "$1" in # When done, sort, sed cuts arugments out of strings and colum make it pretty done | sort | sed -e '/^.*:/d' -e 's/\s[\[\<\-\(].*,/,/' | column -c2 -t -s, if [[ -n "$COMMUNITY_PLUGIN_COMMANDS" ]]; then - echo "" - echo "Community plugin commands:" - echo "" + dokku_log_quiet "" + dokku_log_quiet "Community plugin commands:" + dokku_log_quiet "" for community_plugin_command in $COMMUNITY_PLUGIN_COMMANDS; do $community_plugin_command help done | sort | column -c2 -t -s, diff --git a/plugins/common/functions b/plugins/common/functions index a5ff6caf5..85ca7e5ae 100755 --- a/plugins/common/functions +++ b/plugins/common/functions @@ -16,6 +16,13 @@ dokku_apps() { [[ $INSTALLED_APPS ]] && echo "$INSTALLED_APPS" } +dokku_log_quiet() { + declare desc="log quiet formatter" + if [[ -z "$DOKKU_QUIET_OUTPUT" ]]; then + echo "$*" + fi +} + dokku_log_info1() { declare desc="log info1 formatter" echo "-----> $*" From 6ea86f2714a2c9b3b6029872ad20b8b013c5235a Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Fri, 27 Apr 2018 04:02:08 -0400 Subject: [PATCH 2/7] feat: create bash-completion file This only completes the command names - not any arguments - and also relies on a completion cache as the response from Dokku for help output can be slow. Closes #2095 --- contrib/bash-completion | 39 +++++++++++++++++++++++++++++++++++++++ deb.mk | 2 ++ rpm.mk | 2 ++ 3 files changed, 43 insertions(+) create mode 100644 contrib/bash-completion diff --git a/contrib/bash-completion b/contrib/bash-completion new file mode 100644 index 000000000..fa0fa9b89 --- /dev/null +++ b/contrib/bash-completion @@ -0,0 +1,39 @@ +#!/usr/bin/env bash + +_dokku_complete_goals_fetch() { + dokku --quiet help --all | awk '/^ /{ print $1 }' | sort > "/var/cache/dokku-completion" +} + +_dokku_complete_verify() { + declare desc="shows bash completion" + declare COMMAND="$1" + local COMMANDS="" + + if [[ ! -f "/var/cache/dokku-completion" ]] || [[ -s "/var/cache/dokku-completion" ]]; then + _dokku_complete_goals_fetch + fi + + _dokku_complete_goals=$(cat "/var/cache/dokku-completion") + + while read -r fn; do + if [[ -z "$COMMAND" ]] || [[ "$fn" == $COMMAND* ]]; then + COMMANDS="${COMMANDS};${fn}" + fi + done <<< "$_dokku_complete_goals" + + echo "${COMMANDS#";"}" +} + +have dokku && +_dokku_complete() { + local cur prev + _get_comp_words_by_ref -n : cur + opts=$(_dokku_complete_verify "${cur}") + COMPREPLY=($(IFS=";" compgen -W "$opts" -- "$cur")) + __ltrim_colon_completions "$cur" +} && +complete -F _dokku_complete dokku + +if [[ ! -f "/var/cache/dokku-completion" ]] || [[ -s "/var/cache/dokku-completion" ]]; then + have dokku && export -f _dokku_complete_goals_fetch && nohup bash -c _dokku_complete_goals_fetch >/dev/null 2>&1 & +fi diff --git a/deb.mk b/deb.mk index 74061f2ba..9332c5a02 100644 --- a/deb.mk +++ b/deb.mk @@ -117,6 +117,7 @@ deb-dokku: mkdir -p /tmp/tmp /tmp/build cp -r debian /tmp/build/DEBIAN + mkdir -p /tmp/build/etc/bash_completion.d mkdir -p /tmp/build/usr/bin mkdir -p /tmp/build/usr/share/doc/dokku mkdir -p /tmp/build/usr/share/dokku/contrib @@ -126,6 +127,7 @@ deb-dokku: cp dokku /tmp/build/usr/bin cp LICENSE /tmp/build/usr/share/doc/dokku/copyright + cp contrib/bash-completion /tmp/build/etc/bash_completion.d/dokku find . -name ".DS_Store" -depth -exec rm {} \; $(MAKE) go-build cp common.mk /tmp/build/var/lib/dokku/core-plugins/common.mk diff --git a/rpm.mk b/rpm.mk index ce819f239..083de3917 100644 --- a/rpm.mk +++ b/rpm.mk @@ -51,6 +51,7 @@ rpm-dokku: rm -rf /tmp/tmp /tmp/build dokku_*_$(RPM_ARCHITECTURE).rpm mkdir -p /tmp/tmp /tmp/build + mkdir -p /tmp/build/etc/bash_completion.d mkdir -p /tmp/build/usr/bin mkdir -p /tmp/build/usr/share/doc/dokku mkdir -p /tmp/build/usr/share/dokku/contrib @@ -60,6 +61,7 @@ rpm-dokku: cp dokku /tmp/build/usr/bin cp LICENSE /tmp/build/usr/share/doc/dokku/copyright + cp contrib/bash-completion /tmp/build/etc/bash_completion.d/dokku find . -name ".DS_Store" -depth -exec rm {} \; $(MAKE) go-build cp common.mk /tmp/build/var/lib/dokku/core-plugins/common.mk From 75ea7862cc2c3679f64569da7184eb05f2f756c5 Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Fri, 27 Apr 2018 04:04:36 -0400 Subject: [PATCH 3/7] feat: prime the bash-completion output While not ideal, users can manually update the completion-cache by reconfiguring the installed package, or updating Dokku. --- debian/postinst | 3 +++ rpm/dokku.postinst | 3 +++ 2 files changed, 6 insertions(+) diff --git a/debian/postinst b/debian/postinst index ac40b8e72..bcca83f3b 100755 --- a/debian/postinst +++ b/debian/postinst @@ -80,6 +80,9 @@ case "$1" in echo "Install all core plugins" dokku plugin:install --core + echo "Creating bash-completion cache" + dokku --quiet help --all | awk '/^ /{ print $1 }' | sort > "/var/cache/dokku-completion" + rm -f ${DOKKU_ROOT}/VERSION cp ${DOKKU_LIB_ROOT}/STABLE_VERSION ${DOKKU_ROOT}/VERSION diff --git a/rpm/dokku.postinst b/rpm/dokku.postinst index 4658c75b1..0ce1168fd 100644 --- a/rpm/dokku.postinst +++ b/rpm/dokku.postinst @@ -37,6 +37,9 @@ setup-plugins() { echo "Install all core plugins" dokku plugin:install --core + + echo "Creating bash-completion cache" + dokku --quiet help --all | awk '/^ /{ print $1 }' | sort > "/var/cache/dokku-completion" } setup-sshcommand() { From 172779f3d6097430a2208841318adb775943f1af Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Fri, 27 Apr 2018 04:09:53 -0400 Subject: [PATCH 4/7] feat: recache bash-completion output whenever actions are taken on plugins While this slows down those actions, it ensures we never have out of date information. --- plugins/plugin/internal-functions | 7 +++++++ plugins/plugin/subcommands/disable | 1 + plugins/plugin/subcommands/enable | 1 + plugins/plugin/subcommands/install | 1 + plugins/plugin/subcommands/uninstall | 1 + plugins/plugin/subcommands/update | 1 + 6 files changed, 12 insertions(+) diff --git a/plugins/plugin/internal-functions b/plugins/plugin/internal-functions index 3a417402f..138c9972c 100755 --- a/plugins/plugin/internal-functions +++ b/plugins/plugin/internal-functions @@ -8,3 +8,10 @@ plugin_list_cmd() { plugn version plugn list } + +plugin_prime_bash_completion() { + declare desc="primes the bash-completion cache" + + dokku_log_info1_quiet "Priming bash-completion cache" + dokku --quiet help --all | awk '/^ /{ print $1 }' | sort > "/var/cache/dokku-completion" +} diff --git a/plugins/plugin/subcommands/disable b/plugins/plugin/subcommands/disable index 207b6766a..94efb0a97 100755 --- a/plugins/plugin/subcommands/disable +++ b/plugins/plugin/subcommands/disable @@ -9,6 +9,7 @@ plugin_disable_cmd() { [[ -z $2 ]] && dokku_log_fail "Please specify a plugin to disable" local PLUGIN="$2" disable_plugin "$PLUGIN" + plugin_prime_bash_completion } plugin_disable_cmd "$@" diff --git a/plugins/plugin/subcommands/enable b/plugins/plugin/subcommands/enable index 624393e5b..4b4f24eed 100755 --- a/plugins/plugin/subcommands/enable +++ b/plugins/plugin/subcommands/enable @@ -9,6 +9,7 @@ plugin_enable_cmd() { [[ -z $2 ]] && dokku_log_fail "Please specify a plugin to enable" local PLUGIN="$2" enable_plugin "$PLUGIN" + plugin_prime_bash_completion } plugin_enable_cmd "$@" diff --git a/plugins/plugin/subcommands/install b/plugins/plugin/subcommands/install index 7ff991f3a..8da38b67e 100755 --- a/plugins/plugin/subcommands/install +++ b/plugins/plugin/subcommands/install @@ -20,6 +20,7 @@ plugin_install_cmd() { plugn trigger install ;; esac + plugin_prime_bash_completion } plugin_install_cmd "$@" diff --git a/plugins/plugin/subcommands/uninstall b/plugins/plugin/subcommands/uninstall index 064ee721e..86fbf36b8 100755 --- a/plugins/plugin/subcommands/uninstall +++ b/plugins/plugin/subcommands/uninstall @@ -9,6 +9,7 @@ plugin_uninstall_cmd() { [[ -z $2 ]] && dokku_log_fail "Please specify a plugin to enable" local PLUGIN="$2" uninstall_plugin "$PLUGIN" + plugin_prime_bash_completion } plugin_uninstall_cmd "$@" diff --git a/plugins/plugin/subcommands/update b/plugins/plugin/subcommands/update index 19e82614a..5077b2028 100755 --- a/plugins/plugin/subcommands/update +++ b/plugins/plugin/subcommands/update @@ -10,6 +10,7 @@ plugin_update_cmd() { plugn update "$PLUGIN" "$PLUGIN_COMMITTISH" fi plugn trigger update + plugin_prime_bash_completion } plugin_update_cmd "$@" From 7ee87c7aa5ed11a499a40ca3898e6a02c3595c2a Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Fri, 27 Apr 2018 04:12:30 -0400 Subject: [PATCH 5/7] chore: drop package-based bash-completion priming This is now down in the plugin:install step. --- debian/postinst | 3 --- rpm/dokku.postinst | 3 --- 2 files changed, 6 deletions(-) diff --git a/debian/postinst b/debian/postinst index bcca83f3b..ac40b8e72 100755 --- a/debian/postinst +++ b/debian/postinst @@ -80,9 +80,6 @@ case "$1" in echo "Install all core plugins" dokku plugin:install --core - echo "Creating bash-completion cache" - dokku --quiet help --all | awk '/^ /{ print $1 }' | sort > "/var/cache/dokku-completion" - rm -f ${DOKKU_ROOT}/VERSION cp ${DOKKU_LIB_ROOT}/STABLE_VERSION ${DOKKU_ROOT}/VERSION diff --git a/rpm/dokku.postinst b/rpm/dokku.postinst index 0ce1168fd..4658c75b1 100644 --- a/rpm/dokku.postinst +++ b/rpm/dokku.postinst @@ -37,9 +37,6 @@ setup-plugins() { echo "Install all core plugins" dokku plugin:install --core - - echo "Creating bash-completion cache" - dokku --quiet help --all | awk '/^ /{ print $1 }' | sort > "/var/cache/dokku-completion" } setup-sshcommand() { From 5bfb43222b84e6a693bfbcde2a61cbcba5bafc9e Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Fri, 27 Apr 2018 12:33:33 -0400 Subject: [PATCH 6/7] fix: add missing source --- plugins/plugin/subcommands/disable | 1 + plugins/plugin/subcommands/enable | 1 + plugins/plugin/subcommands/install | 1 + plugins/plugin/subcommands/uninstall | 1 + plugins/plugin/subcommands/update | 1 + 5 files changed, 5 insertions(+) diff --git a/plugins/plugin/subcommands/disable b/plugins/plugin/subcommands/disable index 94efb0a97..96ecda2ef 100755 --- a/plugins/plugin/subcommands/disable +++ b/plugins/plugin/subcommands/disable @@ -2,6 +2,7 @@ set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" source "$PLUGIN_AVAILABLE_PATH/plugin/functions" +source "$PLUGIN_AVAILABLE_PATH/plugin/internal-functions" plugin_disable_cmd() { declare desc="disables plugin via command line" diff --git a/plugins/plugin/subcommands/enable b/plugins/plugin/subcommands/enable index 4b4f24eed..5bc0e0fc6 100755 --- a/plugins/plugin/subcommands/enable +++ b/plugins/plugin/subcommands/enable @@ -2,6 +2,7 @@ set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" source "$PLUGIN_AVAILABLE_PATH/plugin/functions" +source "$PLUGIN_AVAILABLE_PATH/plugin/internal-functions" plugin_enable_cmd() { declare desc="enables plugin via command line" diff --git a/plugins/plugin/subcommands/install b/plugins/plugin/subcommands/install index 8da38b67e..7dab191a1 100755 --- a/plugins/plugin/subcommands/install +++ b/plugins/plugin/subcommands/install @@ -2,6 +2,7 @@ set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" source "$PLUGIN_AVAILABLE_PATH/plugin/functions" +source "$PLUGIN_AVAILABLE_PATH/plugin/internal-functions" plugin_install_cmd() { declare desc="installs a plugin from URL and calls install plugin trigger via command line" diff --git a/plugins/plugin/subcommands/uninstall b/plugins/plugin/subcommands/uninstall index 86fbf36b8..6b3247067 100755 --- a/plugins/plugin/subcommands/uninstall +++ b/plugins/plugin/subcommands/uninstall @@ -2,6 +2,7 @@ set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" source "$PLUGIN_AVAILABLE_PATH/plugin/functions" +source "$PLUGIN_AVAILABLE_PATH/plugin/internal-functions" plugin_uninstall_cmd() { declare desc="uninstalls plugin via command line" diff --git a/plugins/plugin/subcommands/update b/plugins/plugin/subcommands/update index 5077b2028..3c4fbbef9 100755 --- a/plugins/plugin/subcommands/update +++ b/plugins/plugin/subcommands/update @@ -1,5 +1,6 @@ #!/usr/bin/env bash set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x +source "$PLUGIN_AVAILABLE_PATH/plugin/internal-functions" plugin_update_cmd() { declare desc="updates plugin to optional committish and calls update plugin trigger via command line" From 8ac04392f0fc9d2faa11e79f93608040cab40d51 Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Fri, 27 Apr 2018 13:44:29 -0400 Subject: [PATCH 7/7] fix: add missing source --- plugins/plugin/internal-functions | 1 + 1 file changed, 1 insertion(+) diff --git a/plugins/plugin/internal-functions b/plugins/plugin/internal-functions index 138c9972c..35f7db8d1 100755 --- a/plugins/plugin/internal-functions +++ b/plugins/plugin/internal-functions @@ -1,5 +1,6 @@ #!/usr/bin/env bash set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x +source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions" plugin_list_cmd() { declare desc="lists all plugins"