reportist/plugins/consumables/render.sh

38 lines
1.4 KiB
Bash
Executable File

#!/usr/bin/env bash
# Render a Snipe-IT consumables CSV as a stock report.
set -euo pipefail
root=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd -P)
source "$root/../../tools/render-common.sh"
usage() {
echo "Usage: $0 INPUT.csv --output PDF [--theme NAME] [--force]" >&2
exit 2
}
input=${1:-}
[[ -n "$input" ]] || usage
shift
theme=default
options=()
while (($#)); do
case $1 in
--theme) (($# >= 2)) || usage; theme=$2; shift 2 ;;
--output | --force) options+=("$1"); if [[ $1 == --output ]]; then (($# >= 2)) || usage; options+=("$2"); shift 2; else shift; fi ;;
*) usage ;;
esac
done
reportist_parse_render_options consumables "${options[@]}" || usage
[[ -n $RENDER_OUTPUT_OPTION ]] || usage
[[ $input == *.csv && ! -L $input ]] || { echo 'Input must be a regular .csv file' >&2; exit 1; }
reportist_prepare_render_paths "$input" "$RENDER_OUTPUT_OPTION" "$RENDER_FORCE"
input=$RENDER_INPUT output=$RENDER_OUTPUT
reportist_make_render_stage consumables
stage=$RENDER_STAGE
mkdir -p "$stage/consumables" "$stage/config"
cp -- "$root/renderer/render.typ" "$stage/consumables.typ"
cp -- "$root/../../visual/themes.yaml" "$stage/config/themes.yaml"
cp -- "$input" "$stage/consumables/input.csv"
typst compile --root "$stage" --input consumables=consumables/input.csv \
--input "theme=$theme" "$stage/consumables.typ" "$stage/output.pdf"
mv -f -- "$stage/output.pdf" "$output"
echo "Rendered PDF: $output"