diff --git a/docs/development/plugin-triggers.md b/docs/development/plugin-triggers.md index 4326d8adb..95f9da8d2 100644 --- a/docs/development/plugin-triggers.md +++ b/docs/development/plugin-triggers.md @@ -74,6 +74,21 @@ set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x # TODO ``` +### `app-list` + +- Description: Lists all apps in available to the currently logged in user. Optionally disables filtering by user if the first argument is `false`. +- Invoked by: +- Arguments: `$FILTER` +- Example: + +```shell +#!/usr/bin/env bash + +set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x + +# TODO +``` + ### `app-json-process-deploy-parallelism` - Description: Decides the parallelism to use when deploying a given process type. The default is 1 process entry at a type. diff --git a/plugins/common/common.go b/plugins/common/common.go index c4c0cf506..4039fe7d2 100644 --- a/plugins/common/common.go +++ b/plugins/common/common.go @@ -245,6 +245,16 @@ func GetRunningImageTag(appName string, imageTag string) (string, error) { // DokkuApps returns a list of all local apps func DokkuApps() ([]string, error) { + apps, err := UnfilteredDokkuApps() + if err != nil { + return apps, err + } + + return filterApps(apps) +} + +// UnfilteredDokkuApps returns an unfiltered list of all local apps +func UnfilteredDokkuApps() ([]string, error) { apps := []string{} dokkuRoot := MustGetEnv("DOKKU_ROOT") files, err := ioutil.ReadDir(dokkuRoot) @@ -267,7 +277,7 @@ func DokkuApps() ([]string, error) { return apps, fmt.Errorf("You haven't deployed any applications yet") } - return filterApps(apps) + return apps, nil } // GetAppImageName returns image identifier for a given app, tag tuple. validate if tag is presented diff --git a/plugins/common/functions b/plugins/common/functions index 6ed22601f..181fccb27 100755 --- a/plugins/common/functions +++ b/plugins/common/functions @@ -17,7 +17,8 @@ has_tty() { dokku_apps() { declare desc="prints list of all local apps" - local INSTALLED_APPS="$(plugn trigger app-list)" + declare FILTER="$1" + local INSTALLED_APPS="$(plugn trigger app-list "$FILTER")" if [[ -z "$INSTALLED_APPS" ]]; then dokku_log_fail "You haven't deployed any applications yet" fi diff --git a/plugins/common/src/triggers/triggers.go b/plugins/common/src/triggers/triggers.go index 0f911f1ec..35ec4ed26 100644 --- a/plugins/common/src/triggers/triggers.go +++ b/plugins/common/src/triggers/triggers.go @@ -18,7 +18,12 @@ func main() { var err error switch trigger { case "app-list": - err = common.TriggerAppList() + filtered := flag.Arg(0) + if filtered == "" { + filtered = "true" + } + filter := common.ToBool(filtered) + err = common.TriggerAppList(filter) case "core-post-deploy": appName := flag.Arg(0) err = common.TriggerCorePostDeploy(appName) diff --git a/plugins/common/triggers.go b/plugins/common/triggers.go index eccb3b577..5915ccf83 100644 --- a/plugins/common/triggers.go +++ b/plugins/common/triggers.go @@ -6,8 +6,14 @@ import ( ) // TriggerAppList outputs each app name to stdout on a newline -func TriggerAppList() error { - apps, _ := DokkuApps() +func TriggerAppList(filtered bool) error { + var apps []string + if filtered { + apps, _ = DokkuApps() + } else { + apps, _ = UnfilteredDokkuApps() + } + for _, app := range apps { Log(app) }