Skip to content

Commit a5c67a9

Browse files
committed
Add validation for missing values in command line parameters
1 parent 540a8bd commit a5c67a9

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

scripts/analysis/analyze.sh

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,15 +60,31 @@ settingsProfile="Default"
6060
selectedAnalysisDomain=""
6161
exploreMode=false
6262

63+
# Function to check if a parameter value is missing (either empty or another option starting with --)
64+
is_missing_value_parameter() {
65+
case "${2:-}" in
66+
''|--*) return 0 ;; # missing value
67+
*) return 1 ;; # value is present
68+
esac
69+
}
70+
6371
# Parse command line arguments
6472
while [[ $# -gt 0 ]]; do
6573
key="$1"
6674
case $key in
6775
--report)
76+
if is_missing_value_parameter "$1" "$2"; then
77+
echo "analyze: Error: --report requires a value."
78+
usage
79+
fi
6880
analysisReportCompilation="$2"
6981
shift
7082
;;
7183
--profile)
84+
if is_missing_value_parameter "$1" "$2"; then
85+
echo "analyze: Error: --profile requires a value."
86+
usage
87+
fi
7288
settingsProfile="$2"
7389
shift
7490
;;
@@ -77,6 +93,10 @@ while [[ $# -gt 0 ]]; do
7793
shift
7894
;;
7995
--domain)
96+
if is_missing_value_parameter "$1" "$2"; then
97+
echo "analyze: Error: --domain requires a value."
98+
usage
99+
fi
80100
selectedAnalysisDomain="$2"
81101
shift
82102
;;

0 commit comments

Comments
 (0)