feat: add json format output to run:list
Also add some unit tests to the command. Closes #5171
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
@@ -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"
|
||||
}
|
||||
|
||||
@@ -4,18 +4,21 @@ set -eo pipefail
|
||||
source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions"
|
||||
source "$PLUGIN_AVAILABLE_PATH/config/functions"
|
||||
|
||||
trigger-scheduler-docker-local-scheduler-run() {
|
||||
declare desc="runs command in container based on app image"
|
||||
declare trigger="scheduler-run"
|
||||
declare DOKKU_SCHEDULER="$1" APP="$2"
|
||||
trigger-scheduler-docker-local-scheduler-run-list() {
|
||||
declare desc="list run containers for an app"
|
||||
declare trigger="scheduler-run-list"
|
||||
declare DOKKU_SCHEDULER="$1" APP="$2" FORMAT="$3"
|
||||
|
||||
verify_app_name "$APP"
|
||||
if [[ "$DOKKU_SCHEDULER" != "docker-local" ]]; then
|
||||
return
|
||||
fi
|
||||
|
||||
dokku_log_info2_quiet "$APP run containers"
|
||||
docker ps --filter "label=com.dokku.app-name=$APP" --filter "label=com.dokku.container-type=run" --format "table {{.Names}}\t{{.Command}}\t{{.RunningFor}}"
|
||||
if [[ "$FORMAT" == "stdout" ]]; then
|
||||
dokku_log_info2_quiet "$APP run containers"
|
||||
"$DOCKER_BIN" container ls --all --no-trunc --filter "label=com.dokku.app-name=$APP" --filter "label=com.dokku.container-type=run" --format "table {{.Names}}\t{{.Command}}\t{{.RunningFor}}"
|
||||
else
|
||||
"$DOCKER_BIN" container ls --all --no-trunc --filter "label=com.dokku.app-name=$APP" --filter "label=com.dokku.container-type=run" --format "{{ json . }}" | jq -s -M 'map({name: .Names, state:.State, command:.Command, created_at:.CreatedAt})'
|
||||
fi
|
||||
}
|
||||
|
||||
trigger-scheduler-docker-local-scheduler-run "$@"
|
||||
trigger-scheduler-docker-local-scheduler-run-list "$@"
|
||||
|
||||
Reference in New Issue
Block a user