feat: accept --global on :report subcommands

Every `:report` subcommand now recognizes `--global` as a scope selector that limits the report to globally-configured properties, including in JSON form via `--global --format json`. Previously this combination was rejected because `--global` was treated as an info flag, conflicting with `--format`. The shared `common.ParseReportArgs` helper now returns a `ReportArgs` struct exposing the parsed scope; each Go and bash report selects a global-only flag map when scope is global, and skips per-app verification.
This commit is contained in:
Jose Diaz-Gonzalez
2026-04-29 04:47:15 -04:00
parent ec70e10c5d
commit 8282981361
61 changed files with 1379 additions and 518 deletions

View File

@@ -958,3 +958,62 @@ fn-registry-docker-config-dir() {
echo "$config_dir"
fi
}
fn-report-parse-args() {
declare desc="strips --format and --global flags from a report invocation, populating REPORT_FORMAT, REPORT_IS_GLOBAL, REPORT_ARGS"
REPORT_FORMAT="stdout"
REPORT_IS_GLOBAL="false"
REPORT_ARGS=()
while [[ $# -gt 0 ]]; do
case "$1" in
--format)
REPORT_FORMAT="$2"
shift 2
;;
--global)
REPORT_IS_GLOBAL="true"
shift
;;
*)
REPORT_ARGS+=("$1")
shift
;;
esac
done
}
fn-report-emit-json() {
declare desc="serializes a flag_map array (passed by name) as a JSON object, stripping the --<prefix>- prefix from each key"
declare flag_map_name="$1" prefix="$2"
local -n flag_map_ref="$flag_map_name"
local json_output="{}"
for flag in "${flag_map_ref[@]}"; do
local key value
key="$(echo "$flag" | cut -d':' -f1 | sed "s/^--${prefix}-//")"
value="$(echo "$flag" | cut -d':' -f2- | sed 's/^ //')"
json_output="$(echo "$json_output" | jq -c --arg key "$key" --arg value "$value" '. + {($key): $value}')"
done
echo "$json_output"
}
fn-report-filter-global() {
declare desc="filters a flag_map array (passed by name) in place, keeping only entries with -global- in their flag name"
declare flag_map_name="$1"
local -n flag_map_ref="$flag_map_name"
local filtered=()
for flag in "${flag_map_ref[@]}"; do
local key="$(echo "$flag" | cut -d':' -f1)"
if [[ "$key" == *"-global-"* ]]; then
filtered+=("$flag")
fi
done
flag_map_ref=("${filtered[@]}")
}
fn-report-validate-format() {
declare desc="rejects --format json when an info flag is also specified"
declare FORMAT="$1" INFO_FLAG="$2"
if [[ "$FORMAT" != "stdout" ]] && [[ -n "$INFO_FLAG" ]]; then
dokku_log_fail "--format flag cannot be specified when specifying an info flag"
fi
}