From b268af7cb7a1c82bf86edce760afe92a66b0d7ad Mon Sep 17 00:00:00 2001 From: Dandaedre Date: Wed, 16 Sep 2026 21:07:18 +0200 Subject: [PATCH] Format Reportist shell entry points consistently --- build.sh | 48 ++++++++++++++++++++++++++--------- plugins/diagnostics/render.sh | 14 +++++++--- render.sh | 16 +++++++++--- tools/export-json-all.sh | 17 ++++++++++--- tools/render-common.sh | 12 ++++++--- tools/validate-all.sh | 16 +++++++++--- tools/validate.sh | 5 +++- 7 files changed, 98 insertions(+), 30 deletions(-) diff --git a/build.sh b/build.sh index 662fbf1..be72cf1 100755 --- a/build.sh +++ b/build.sh @@ -25,24 +25,42 @@ kind_command() { esac } -command_name=${1:-}; [[ -n "$command_name" ]] || usage; shift +command_name=${1:-} +[[ -n "$command_name" ]] || usage +shift case "$command_name" in render) (($# >= 4)) || usage - kind=$1; input=$2; shift 2 + kind=$1 + input=$2 + shift 2 renderer=$(kind_command "$kind") exec "$renderer" "$input" "$@" ;; render-all) (($# >= 4)) || usage - kind=$1; input_dir=$2; shift 2 + kind=$1 + input_dir=$2 + shift 2 kind_command "$kind" >/dev/null - output_dir=; options=() + output_dir= + options=() while (($#)); do case $1 in - --output-dir) (($# >= 2)) || usage; output_dir=$2; shift 2 ;; - --force) options+=(--force); shift ;; - --author|--theme) (($# >= 2)) || usage; options+=("$1" "$2"); shift 2 ;; + --output-dir) + (($# >= 2)) || usage + output_dir=$2 + shift 2 + ;; + --force) + options+=(--force) + shift + ;; + --author | --theme) + (($# >= 2)) || usage + options+=("$1" "$2") + shift 2 + ;; *) usage ;; esac done @@ -51,13 +69,14 @@ case "$command_name" in mkdir -p "$output_dir" output_dir=$(realpath "$output_dir") [[ "$output_dir" != "$input_dir" && "$output_dir" != "$input_dir"/* ]] || { - echo 'Output directory must be outside the input tree' >&2; exit 1; + echo 'Output directory must be outside the input tree' >&2 + exit 1 } count=0 while IFS= read -r -d '' input; do relative=${input#"$input_dir/"} case "$kind:$input" in - report:*.yaml|report:*.yml|report:*.json|diagnostic:*.json) ;; + report:*.yaml | report:*.yml | report:*.json | diagnostic:*.json) ;; *) continue ;; esac output="$output_dir/${relative%.*}.pdf" @@ -65,7 +84,10 @@ case "$command_name" in "$root/build.sh" render "$kind" "$input" --output "$output" "${options[@]}" ((count += 1)) done < <(find "$input_dir" -type f -print0) - ((count > 0)) || { echo 'No matching input files' >&2; exit 1; } + ((count > 0)) || { + echo 'No matching input files' >&2 + exit 1 + } echo "Rendered $count $kind PDFs into $output_dir" ;; analyze) @@ -76,7 +98,8 @@ case "$command_name" in ;; validate) (($# >= 2)) || usage - kind=$1; shift + kind=$1 + shift case $kind in report) exec "$root/tools/validate.sh" "$@" ;; diagnostic) exec "$root/plugins/diagnostics/tools/validate.sh" "$@" ;; @@ -85,7 +108,8 @@ case "$command_name" in ;; validate-all) (($# >= 2)) || usage - kind=$1; shift + kind=$1 + shift case $kind in report) exec "$root/tools/validate-all.sh" "$@" ;; diagnostic) exec "$root/plugins/diagnostics/tools/validate-all.sh" "$@" ;; diff --git a/plugins/diagnostics/render.sh b/plugins/diagnostics/render.sh index 0fbfac3..9212257 100755 --- a/plugins/diagnostics/render.sh +++ b/plugins/diagnostics/render.sh @@ -4,9 +4,17 @@ set -euo pipefail root=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd -P) source "$root/../../tools/render-common.sh" visual_root=$root/../../visual -usage() { echo "Usage: $0 CAPTURE.json --output PDF [--author NAME] [--theme default|cic|eridani] [--force]" >&2; exit 2; } -fail() { echo "error: $*" >&2; exit 1; } -input=${1:-}; [[ -n "$input" ]] || usage; shift +usage() { + echo "Usage: $0 CAPTURE.json --output PDF [--author NAME] [--theme default|cic|eridani] [--force]" >&2 + exit 2 +} +fail() { + echo "error: $*" >&2 + exit 1 +} +input=${1:-} +[[ -n "$input" ]] || usage +shift reportist_parse_render_options diagnostic "$@" || usage output=$RENDER_OUTPUT_OPTION author=$RENDER_AUTHOR theme=$RENDER_THEME force=$RENDER_FORCE [[ "$theme" == default || "$theme" == cic || "$theme" == eridani ]] || fail "unknown theme: $theme" diff --git a/render.sh b/render.sh index 4671b7b..a813470 100755 --- a/render.sh +++ b/render.sh @@ -3,12 +3,20 @@ set -euo pipefail root=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd -P) source "$root/tools/render-common.sh" -usage() { echo "Usage: $0 INPUT.yaml|json [--output PDF] [--typst COMMAND] [--force]" >&2; exit 2; } -fail() { echo "error: $*" >&2; exit 1; } -input=${1:-}; [[ -n "$input" ]] || usage; shift +usage() { + echo "Usage: $0 INPUT.yaml|json [--output PDF] [--typst COMMAND] [--force]" >&2 + exit 2 +} +fail() { + echo "error: $*" >&2 + exit 1 +} +input=${1:-} +[[ -n "$input" ]] || usage +shift reportist_parse_render_options report "$@" || usage output=$RENDER_OUTPUT_OPTION typst_command=$RENDER_TYPST force=$RENDER_FORCE -case $input in *.yaml|*.yml) format=yaml;; *.json) format=json;; *) fail "expected a YAML or JSON report";; esac +case $input in *.yaml | *.yml) format=yaml ;; *.json) format=json ;; *) fail "expected a YAML or JSON report" ;; esac command -v "$typst_command" >/dev/null 2>&1 || fail "Typst executable not found: $typst_command" if [[ -z "$output" ]]; then output=${input%.*}.pdf; fi reportist_prepare_render_paths "$input" "$output" "$force" || exit 1 diff --git a/tools/export-json-all.sh b/tools/export-json-all.sh index a5f4c18..0d2af5a 100755 --- a/tools/export-json-all.sh +++ b/tools/export-json-all.sh @@ -1,11 +1,17 @@ #!/usr/bin/env bash set -euo pipefail root=$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd -P) -[[ $# -eq 3 && $2 == --output-dir ]]||{ echo "Usage: $0 INPUT_DIR --output-dir DIR" >&2; exit 2; } +[[ $# -eq 3 && $2 == --output-dir ]] || { + echo "Usage: $0 INPUT_DIR --output-dir DIR" >&2 + exit 2 +} input_dir=$(realpath "$1") mkdir -p "$3" output_dir=$(realpath "$3") -[[ "$output_dir" != "$input_dir" && "$output_dir" != "$input_dir"/* ]]||{ echo "output directory must be outside the input tree" >&2; exit 1; } +[[ "$output_dir" != "$input_dir" && "$output_dir" != "$input_dir"/* ]] || { + echo "output directory must be outside the input tree" >&2 + exit 1 +} count=0 while IFS= read -r -d '' input; do relative=${input#"$input_dir/"} @@ -19,7 +25,10 @@ while IFS= read -r -d '' input; do 'query().first().value' >"$output" rm -rf "$stage" trap - EXIT - ((count+=1)) + ((count += 1)) done < <(find "$input_dir" -type f \( -name '*.yaml' -o -name '*.yml' \) -print0) -((count > 0))||{ echo "$input_dir: no YAML reports found" >&2; exit 1; } +((count > 0)) || { + echo "$input_dir: no YAML reports found" >&2 + exit 1 +} echo "Exported $count report JSON files into $output_dir" diff --git a/tools/render-common.sh b/tools/render-common.sh index c21dceb..267668d 100644 --- a/tools/render-common.sh +++ b/tools/render-common.sh @@ -19,7 +19,7 @@ reportist_parse_render_options() { RENDER_FORCE=true shift ;; - --author|--theme) + --author | --theme) [[ $kind == diagnostic && $# -ge 2 ]] || return 2 if [[ $1 == --author ]]; then RENDER_AUTHOR=$2; else RENDER_THEME=$2; fi shift 2 @@ -38,11 +38,17 @@ reportist_parse_render_options() { reportist_prepare_render_paths() { local source=$1 destination=$2 replace=$3 parent RENDER_INPUT=$(realpath "$source") - [[ -f "$RENDER_INPUT" ]] || { echo "$source: input does not exist" >&2; return 1; } + [[ -f "$RENDER_INPUT" ]] || { + echo "$source: input does not exist" >&2 + return 1 + } parent=$(dirname "$destination") mkdir -p "$parent" RENDER_OUTPUT=$(cd "$parent" && pwd -P)/$(basename "$destination") - [[ "$RENDER_INPUT" != "$RENDER_OUTPUT" ]] || { echo 'Input and output paths must differ' >&2; return 1; } + [[ "$RENDER_INPUT" != "$RENDER_OUTPUT" ]] || { + echo 'Input and output paths must differ' >&2 + return 1 + } [[ ! -e "$RENDER_OUTPUT" || "$replace" == true ]] || { echo "$RENDER_OUTPUT: output exists; use --force to replace it" >&2 return 1 diff --git a/tools/validate-all.sh b/tools/validate-all.sh index 65db7db..b253ef6 100755 --- a/tools/validate-all.sh +++ b/tools/validate-all.sh @@ -1,9 +1,19 @@ #!/usr/bin/env bash set -euo pipefail root=$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd -P) -input_dir=${1:-}; [[ -n "$input_dir" && $# -eq 1 ]]||{ echo "Usage: $0 INPUT_DIR" >&2; exit 2; } +input_dir=${1:-} +[[ -n "$input_dir" && $# -eq 1 ]] || { + echo "Usage: $0 INPUT_DIR" >&2 + exit 2 +} count=0 -while IFS= read -r -d '' input; do "$root/tools/validate.sh" "$input"; ((count+=1)); done \ +while IFS= read -r -d '' input; do + "$root/tools/validate.sh" "$input" + ((count += 1)) +done \ < <(find "$input_dir" -type f \( -name '*.json' -o -name '*.yaml' -o -name '*.yml' \) -print0) -((count > 0))||{ echo "$input_dir: no YAML or JSON reports found" >&2; exit 1; } +((count > 0)) || { + echo "$input_dir: no YAML or JSON reports found" >&2 + exit 1 +} echo "Validated $count reports" diff --git a/tools/validate.sh b/tools/validate.sh index d7d27a1..fab1792 100755 --- a/tools/validate.sh +++ b/tools/validate.sh @@ -1,7 +1,10 @@ #!/usr/bin/env bash # Validate only what the report plugin itself requires to render. set -euo pipefail -[[ $# -eq 1 ]] || { echo "Usage: $0 INPUT" >&2; exit 2; } +[[ $# -eq 1 ]] || { + echo "Usage: $0 INPUT" >&2 + exit 2 +} root=$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd -P) stage=$(mktemp -d "${TMPDIR:-/tmp}/beffroi-report-validate.XXXXXXXX") trap 'rm -rf -- "$stage"' EXIT