chore(scripts): improve CLI option parsing and error handling
All checks were successful
Auto Changelog & Release / release (push) Successful in 7s

This commit is contained in:
2025-12-14 10:04:56 +01:00
parent 7e23c3f8ec
commit f6c99d11e2
2 changed files with 127 additions and 31 deletions

View File

@@ -60,24 +60,67 @@ show_help() {
# 1 ─ Parse CLI options ─────────────────────────
while [[ $# -gt 0 ]]; do
case "$1" in
--version) VERSION="$2"; shift 2 ;;
--tag) TAG="$2"; shift 2 ;;
--package_name) PACKAGE_NAME="$2"; shift 2 ;;
--author_name) AUTHOR_NAME="$2"; shift 2 ;;
--author_email) AUTHOR_EMAIL="$2"; shift 2 ;;
--output_file) OUTPUT_FILE="$2"; shift 2 ;;
--cliff_config) CLIFF_CONFIG="$2"; shift 2 ;;
-h|--help) show_help; exit 0 ;;
*) echo "❌ Unknown option: $1"; show_help; exit 1 ;;
--version)
VERSION="$2"
shift 2
;;
--tag)
TAG="$2"
shift 2
;;
--package_name)
PACKAGE_NAME="$2"
shift 2
;;
--author_name)
AUTHOR_NAME="$2"
shift 2
;;
--author_email)
AUTHOR_EMAIL="$2"
shift 2
;;
--output_file)
OUTPUT_FILE="$2"
shift 2
;;
--cliff_config)
CLIFF_CONFIG="$2"
shift 2
;;
-h | --help)
show_help
exit 0
;;
*)
echo "❌ Unknown option: $1"
show_help
exit 1
;;
esac
done
# 2 ─ Validate mandatory inputs ────────────────
[[ -z "$VERSION" ]] && { echo "❌ --version is required"; exit 1; }
[[ -z "$TAG" ]] && { echo "❌ --tag is required"; exit 1; }
[[ -z "$PACKAGE_NAME" ]] && { echo "❌ --package_name is required"; exit 1; }
[[ -z "$AUTHOR_NAME" ]] && { echo "❌ --author_name is required"; exit 1; }
[[ -z "$AUTHOR_EMAIL" ]] && { echo "❌ --author_email is required"; exit 1; }
[[ -z "$VERSION" ]] && {
echo "❌ --version is required"
exit 1
}
[[ -z "$TAG" ]] && {
echo "❌ --tag is required"
exit 1
}
[[ -z "$PACKAGE_NAME" ]] && {
echo "❌ --package_name is required"
exit 1
}
[[ -z "$AUTHOR_NAME" ]] && {
echo "❌ --author_name is required"
exit 1
}
[[ -z "$AUTHOR_EMAIL" ]] && {
echo "❌ --author_email is required"
exit 1
}
# 3 ─ Prepare temporary clone ──────────────────
TMP_DIR=$(mktemp -d)
@@ -94,7 +137,10 @@ bash "$TMP_DIR/scripts/install-git-cliff.sh"
if [[ -z "$CLIFF_CONFIG" ]]; then
CLIFF_CONFIG="$TMP_DIR/configs/cliff.debian.toml"
fi
[[ ! -r "$CLIFF_CONFIG" ]] && { echo "❌ Config not found: $CLIFF_CONFIG"; exit 1; }
[[ ! -r "$CLIFF_CONFIG" ]] && {
echo "❌ Config not found: $CLIFF_CONFIG"
exit 1
}
# 6 ─ Generate changelog in CURRENT dir ────────
echo "📝 Generating changelog (output → $OUTPUT_FILE)"

View File

@@ -39,27 +39,77 @@ show_help() {
# 1 Parse CLI options
while [[ $# -gt 0 ]]; do
case "$1" in
-c|--config) [[ $# -lt 2 ]] && { echo "$1 requires a value"; exit 1; }; CONFIG_FILE="$2"; shift 2 ;;
-t|--tag) [[ $# -lt 2 ]] && { echo "$1 requires a value"; exit 1; }; TAG="$2"; shift 2 ;;
-o|--out) [[ $# -lt 2 ]] && { echo "$1 requires a value"; exit 1; }; OUT_FILE="$2"; shift 2 ;;
-d|--debug) DEBUG=true; shift ;;
-h|--help) show_help; exit 0 ;;
*) echo "❌ Unknown option: $1"; show_help; exit 1 ;;
-c | --config)
[[ $# -lt 2 ]] && {
echo "$1 requires a value"
exit 1
}
CONFIG_FILE="$2"
shift 2
;;
-t | --tag)
[[ $# -lt 2 ]] && {
echo "$1 requires a value"
exit 1
}
TAG="$2"
shift 2
;;
-o | --out)
[[ $# -lt 2 ]] && {
echo "$1 requires a value"
exit 1
}
OUT_FILE="$2"
shift 2
;;
-d | --debug)
DEBUG=true
shift
;;
-h | --help)
show_help
exit 0
;;
*)
echo "❌ Unknown option: $1"
show_help
exit 1
;;
esac
done
# 2 Basic validation
[[ -z "$CONFIG_FILE" || -z "$TAG" ]] && { echo "❌ --config and --tag are required"; show_help; exit 1; }
[[ "$DEBUG" = false && -z "$OUT_FILE" ]] && { echo "❌ --out is required unless --debug is set"; show_help; exit 1; }
[[ ! -r "$CONFIG_FILE" ]] && { echo "❌ Config file not found or unreadable: $CONFIG_FILE"; exit 1; }
[[ -z "$CONFIG_FILE" || -z "$TAG" ]] && {
echo "❌ --config and --tag are required"
show_help
exit 1
}
[[ "$DEBUG" = false && -z "$OUT_FILE" ]] && {
echo "❌ --out is required unless --debug is set"
show_help
exit 1
}
[[ ! -r "$CONFIG_FILE" ]] && {
echo "❌ Config file not found or unreadable: $CONFIG_FILE"
exit 1
}
if [[ "$DEBUG" = false ]]; then
OUT_DIR=$(dirname "$OUT_FILE")
[[ ! -d "$OUT_DIR" ]] && { echo "❌ Output directory does not exist: $OUT_DIR"; exit 1; }
[[ ! -d "$OUT_DIR" ]] && {
echo "❌ Output directory does not exist: $OUT_DIR"
exit 1
}
fi
# 3 Required tools
need() { command -v "$1" >/dev/null || { echo "$1 is required but not installed"; exit 1; }; }
need git; need git-cliff; need sed
need() { command -v "$1" >/dev/null || {
echo "$1 is required but not installed"
exit 1
}; }
need git
need git-cliff
need sed
# 4 Generate changelog
if $DEBUG; then