#!/bin/bash

# Regenerate the simul_efun help files in /doc/sefun from the LPCDoc comment
# blocks in /adm/simul_efun, using BeDoc (https://github.com/gesslar/BeDoc).
#
# The parser, formatter and per-function writer hook live under /doc/bedoc; the
# config that ties them together is /doc/bedoc/sefun.json5. Any extra arguments
# are passed straight through to bedoc (e.g. --terse).

CURR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &> /dev/null && pwd)
LIB="$CURR/../.."        # adm/bash -> lib root

cd "$LIB" || exit 1

# Clean rebuild: clear out the generated help files (and the scratch module
# output) first so renamed or removed sefuns don't leave orphans behind.
rm -f doc/sefun/*.help tmp/bedoc/*

npx -y @gesslar/bedoc --config doc/bedoc/sefun.json5 "$@"
