From c7f511c5f22c9e7c0846df318b1eecb2a334c144 Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Mon, 15 Jul 2019 14:59:05 -0700 Subject: [PATCH] feat: add service:links command This allows users to script against apps that are linked to a given service --- common-functions | 14 +++++++++++++- subcommands/links | 24 ++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 1 deletion(-) create mode 100755 subcommands/links diff --git a/common-functions b/common-functions index f9ccfe4..df0534c 100755 --- a/common-functions +++ b/common-functions @@ -468,7 +468,7 @@ service_link() { } service_linked_apps() { - declare desc="Lists all applications linked to a service" + declare desc="Lists all apps linked to a service for info output" declare SERVICE="$1" local SERVICE_ROOT="$PLUGIN_DATA_ROOT/$SERVICE" local LINKS_FILE="$SERVICE_ROOT/LINKS" @@ -479,6 +479,18 @@ service_linked_apps() { tr '\n' ' ' <"$LINKS_FILE" } +service_links() { + declare desc="Lists all apps linked to a service" + declare SERVICE="$1" + local SERVICE_ROOT="$PLUGIN_DATA_ROOT/$SERVICE" + local LINKS_FILE="$SERVICE_ROOT/LINKS" + + touch "$LINKS_FILE" + [[ -z $(<"$LINKS_FILE") ]] && return 0 + + cat "$LINKS_FILE" +} + service_list() { declare desc="Lists all services and their status" local SERVICES=$(ls "$PLUGIN_DATA_ROOT" 2>/dev/null) diff --git a/subcommands/links b/subcommands/links new file mode 100755 index 0000000..a2e49b0 --- /dev/null +++ b/subcommands/links @@ -0,0 +1,24 @@ +#!/usr/bin/env bash +source "$(dirname "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)")/config" +set -eo pipefail +[[ $DOKKU_TRACE ]] && set -x +source "$PLUGIN_BASE_PATH/common/functions" +source "$(dirname "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)")/functions" + +service-links-cmd() { + #E list all apps linked to the 'lolipop' $PLUGIN_COMMAND_PREFIX service. + #E dokku $PLUGIN_COMMAND_PREFIX:links lolipop + #A service, service to run command against + declare desc="list all apps linked to the $PLUGIN_SERVICE service" + local cmd="$PLUGIN_COMMAND_PREFIX:links" argv=("$@") + [[ ${argv[0]} == "$cmd" ]] && shift 1 + declare SERVICE="$1" + local SERVICE_ROOT="$PLUGIN_DATA_ROOT/$SERVICE" + local LINKS_FILE="$SERVICE_ROOT/LINKS" + + [[ -z "$SERVICE" ]] && dokku_log_fail "Please specify a valid name for the service" + verify_service_name "$SERVICE" + service_links "$SERVICE" +} + +service-links-cmd "$@"