feat: add the ability to specify a remote via the --remote flag

Closes #2523
This commit is contained in:
Jose Diaz-Gonzalez committed 2017-01-09 01:15:22 -07:00
1 parent 70f3e3407f
commit 5ddcf06ce9
1 file changed
+34 -18
+34 -18
View File
@@ -1,5 +1,7 @@
#!/usr/bin/env bash #!/usr/bin/env bash
set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x
export DOKKU_PORT=${DOKKU_PORT:=22}
export DOKKU_HOST=${DOKKU_HOST:=}
fn-random-number() { fn-random-number() {
[[ -n "$1" ]] && RANGE="$1" [[ -n "$1" ]] && RANGE="$1"
@@ -39,21 +41,38 @@ fn-is-git-repo() {
} }
fn-has-dokku-remote() { fn-has-dokku-remote() {
git remote show | grep dokku git remote show | grep -E "^${DOKKU_GIT_REMOTE}\s"
} }
if [[ -z $DOKKU_HOST ]]; then fn-dokku-host() {
declare DOKKU_GIT_REMOTE="$1" DOKKU_HOST="$2"
if [[ -z "$DOKKU_HOST" ]]; then
if [[ -d .git ]] || git rev-parse --git-dir > /dev/null 2>&1; then if [[ -d .git ]] || git rev-parse --git-dir > /dev/null 2>&1; then
DOKKU_HOST=$(git remote -v 2>/dev/null | grep -Ei "^dokku" | head -n 1 | cut -f1 -d' ' | cut -f2 -d '@' | cut -f1 -d':' 2>/dev/null || true) DOKKU_HOST=$(git remote -v 2>/dev/null | grep -Ei "^${DOKKU_GIT_REMOTE}\s" | head -n 1 | cut -f1 -d' ' | cut -f2 -d '@' | cut -f1 -d':' 2>/dev/null || true)
else fi
fn-client-help-msg
fi fi
fi
export DOKKU_PORT=${DOKKU_PORT:=22} echo "$DOKKU_HOST"
}
main() {
local DOKKU_GIT_REMOTE
local next_index=1; local skip=false; local args=("$@")
for arg in "$@"; do
$skip && break
case "$arg" in
--remote)
DOKKU_GIT_REMOTE=${args[$next_index]}
skip=true
shift 2
;;
esac
done
DOKKU_HOST="$(fn-dokku-host "$DOKKU_GIT_REMOTE" "$DOKKU_HOST")"
if [[ ! -z $DOKKU_HOST ]]; then
_dokku() {
appname="" appname=""
if [[ -d .git ]] || git rev-parse --git-dir > /dev/null 2>&1; then if [[ -d .git ]] || git rev-parse --git-dir > /dev/null 2>&1; then
set +e set +e
@@ -82,15 +101,15 @@ if [[ ! -z $DOKKU_HOST ]]; then
appname="$2" appname="$2"
fi fi
if git remote add dokku "dokku@$DOKKU_HOST:$appname"; then if git remote add dokku "dokku@$DOKKU_HOST:$appname"; then
echo "-----> Dokku remote added at $DOKKU_HOST" echo "-----> Dokku remote added at ${DOKKU_HOST} called ${DOKKU_GIT_REMOTE}"
echo "-----> Application name is $appname" echo "-----> Application name is ${appname}"
else else
echo "! Dokku remote not added! Do you already have a dokku remote?" echo "! Dokku remote not added! Do you already have a dokku remote?"
return return
fi fi
;; ;;
apps:destroy) apps:destroy)
fn-is-git-repo && fn-has-dokku-remote && git remote remove dokku fn-is-git-repo && fn-has-dokku-remote && git remote remove "$DOKKU_GIT_REMOTE"
;; ;;
esac esac
@@ -98,12 +117,9 @@ if [[ ! -z $DOKKU_HOST ]]; then
# echo "ssh -o LogLevel=QUIET -p $DOKKU_PORT -t dokku@$DOKKU_HOST -- $app_arg $@" # echo "ssh -o LogLevel=QUIET -p $DOKKU_PORT -t dokku@$DOKKU_HOST -- $app_arg $@"
# shellcheck disable=SC2068,SC2086 # shellcheck disable=SC2068,SC2086
ssh -o LogLevel=QUIET -p $DOKKU_PORT -t dokku@$DOKKU_HOST -- $app_arg $@ ssh -o LogLevel=QUIET -p $DOKKU_PORT -t dokku@$DOKKU_HOST -- $app_arg $@
} }
if [[ "$0" == "dokku" ]] || [[ "$0" == *dokku_client.sh ]] || [[ "$0" == $(which dokku) ]]; then if [[ "$0" == "dokku" ]] || [[ "$0" == *dokku_client.sh ]] || [[ "$0" == $(which dokku) ]]; then
_dokku "$@" main "$@"
exit $? exit $?
fi
else
fn-client-help-msg
fi fi