#!/usr/bin/env sh
# SPDX-FileCopyrightText: 2025 Robin Vobruba <hoijui.quaero@gmail.com>
# SPDX-License-Identifier: Unlicense

# Exit immediately on each error and unset variable;
# see: https://vaneyckt.io/posts/safer_bash_scripts_with_set_euxo_pipefail/
#set -Eeuo pipefail
set -eu

script_path="$(readlink -f "$0")"
script_dir="$(dirname "$script_path")"
script_name="$(basename "$script_path")"

root_dir="$script_dir/.."

_print_help() {

	echo "Lints all Markdown source files in hte project."
	echo
	echo "Usage:"
	echo "  $script_name [OPTIONS]"
	echo "Options:"
	echo "  -h, --help"
	echo "     Show this help message and exit"
	echo "Examples:"
	echo "  $script_name"
	echo "  $script_name --help"
}

# read command-line args
i=1
while [ "$i" -le "$#" ]
do
	arg="$(eval "echo \$$i")"

	case "$arg" in
		-h|--help)
			shift "$i"
			_print_help
			exit 0
			;;
		*) # non-/unknown option
			i=$((i + 1))
			;;
	esac
done

find doc res src README.md CODE_OF_CONDUCT.md \
	-name '*.md' \
	| xargs mdl \
	--config .mdlrc
