feat: add json format output to run:list

Also add some unit tests to the command.

Closes #5171
This commit is contained in:
Jose Diaz-Gonzalez
2022-08-22 22:25:46 -04:00
parent 6348126f0c
commit 69738abec2
6 changed files with 137 additions and 17 deletions

View File

@@ -29,6 +29,6 @@ fn-help-content() {
cat <<help_content
run [-e|--env KEY=VALUE] [--no-tty] <app> <cmd>, Run a command in a new container using the current app image
run:detached [-e|-env KEY=VALUE] [--no-tty] <app> <cmd>, Run a command in a new detached container using the current app image
run:list <app>, List all run containers for an app
run:list [--format json|stdout] <app>, List all run containers for an app
help_content
}

View File

@@ -80,8 +80,32 @@ cmd-run-list() {
declare desc="list all run containers for an app"
declare cmd="run:list"
[[ "$1" == "$cmd" ]] && shift 1
declare APP="$1"
declare APP=""
local FORMAT="stdout"
while [[ $# -gt 0 ]]; do
case $1 in
--format=*)
local arg=$(printf "%s" "$1" | sed -E 's/(^--format=)//g')
FORMAT="$arg"
shift
;;
--format)
if [[ ! $2 ]]; then
dokku_log_warn "expected $1 to have an argument"
break
fi
FORMAT="$2"
shift 2
;;
*)
APP="$1"
shift
;;
esac
done
verify_app_name "$APP"
local DOKKU_SCHEDULER=$(get_app_scheduler "$APP")
plugn trigger scheduler-run-list "$DOKKU_SCHEDULER" "$APP"
plugn trigger scheduler-run-list "$DOKKU_SCHEDULER" "$APP" "$FORMAT"
}