From 44901f4bdc6d4a9dd25a2e482fa3e23e16e1507b Mon Sep 17 00:00:00 2001 From: Mahmoud Ashraf <182176867+SNO7E-G@users.noreply.github.com> Date: Thu, 23 Jul 2026 22:20:20 +0500 Subject: [PATCH] Fail cleanly when an option is missing its value Value-taking options in the argument parser read "$2" without checking it exists. Under `set -u`, invoking one with no value (e.g. `ptc-cli.sh -s en -p`) aborted with a raw "$2: unbound variable" instead of a usable message. Guard the value-taking options at the top of the parse loop: a missing value now logs "Option '' requires a value." and exits 1. The "--opt=value" forms carry their value in $1 and are exempt. --- ptc-cli.sh | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/ptc-cli.sh b/ptc-cli.sh index 747db3b..1d63b4e 100755 --- a/ptc-cli.sh +++ b/ptc-cli.sh @@ -3198,6 +3198,18 @@ main() { # Argument parsing while [[ $# -gt 0 ]]; do + # A value-taking option with no value left would read an unbound "$2" + # and, under `set -u`, abort with a raw bash error. Fail cleanly instead. + # (The "--opt=value" forms carry their value in $1 and are exempt.) + case "$1" in + -s|--source-locale|-p|--patterns|-c|--config-file|-t|--file-tag-name|-d|--project-dir|--api-url|--api-token|--monitor-interval|--monitor-max-attempts|--action) + if [[ $# -lt 2 ]]; then + log_error "Option '$1' requires a value." + echo "Use --help for help" + exit 1 + fi + ;; + esac case $1 in -s|--source-locale) PTC_SOURCE_LOCALE="$2"