-
Notifications
You must be signed in to change notification settings - Fork 4
Created common script argument parsing #60
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -57,44 +57,18 @@ if [[ -z $PRESTO_DATA_DIR ]]; then | |
| exit 1 | ||
| fi | ||
|
|
||
| source ./common_functions.sh | ||
| source ../../scripts/helper_functions.sh | ||
|
|
||
| wait_for_worker_node_registration | ||
| declare -A OPTION_MAP=( ["-b"]="--benchmark-type" | ||
| ["-d"]="--data-dir-name" | ||
| ["-s"]="--schema-name" ) | ||
| make_options "OPTION_MAP" | ||
|
|
||
| parse_args() { | ||
| custom_parse_args() { | ||
| while [[ $# -gt 0 ]]; do | ||
| case $1 in | ||
| -h|--help) | ||
| print_help | ||
| exit 0 | ||
| ;; | ||
| -b|--benchmark-type) | ||
| if [[ -n $2 ]]; then | ||
| BENCHMARK_TYPE=$2 | ||
| shift 2 | ||
| else | ||
| echo "Error: --benchmark-type requires a value" | ||
| exit 1 | ||
| fi | ||
| ;; | ||
| -s|--schema-name) | ||
| if [[ -n $2 ]]; then | ||
| SCHEMA_NAME=$2 | ||
| shift 2 | ||
| else | ||
| echo "Error: --schema-name requires a value" | ||
| exit 1 | ||
| fi | ||
| ;; | ||
| -d|--data-dir-name) | ||
| if [[ -n $2 ]]; then | ||
| DATA_DIR_NAME=$2 | ||
| shift 2 | ||
| else | ||
| echo "Error: --data-dir-name requires a value" | ||
| exit 1 | ||
| fi | ||
| ;; | ||
| -h|--help) print_help; exit 0;; | ||
| $OPTIONS) parse_option $1 $2; shift 2;; | ||
| -c|--convert-decimals-to-floats) | ||
| CONVERT_DECIMALS_TO_FLOATS_ARG="--convert-decimals-to-floats" | ||
| shift | ||
|
|
@@ -118,7 +92,11 @@ parse_args() { | |
| done | ||
| } | ||
|
|
||
| parse_args "$@" | ||
| custom_parse_args "$@" | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Moved argument parsing before waiting on worker node so the user can use functions like "--help" without having to wait for a worker registration. |
||
|
|
||
| source ./common_functions.sh | ||
|
|
||
| wait_for_worker_node_registration | ||
|
|
||
| if [[ -z ${BENCHMARK_TYPE} || ! ${BENCHMARK_TYPE} =~ ^tpc(h|ds)$ ]]; then | ||
| echo "Error: A valid benchmark type (tpch or tpcds) is required. Use the -b or --benchmark-type argument." | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,6 +16,8 @@ | |
|
|
||
| set -e | ||
|
|
||
| source ./start_presto_helper_parse_args.sh | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Moved this up so the user can use "--help" before running into the ENV variable validation. |
||
|
|
||
| if [[ -z ${VARIANT_TYPE} || ! ${VARIANT_TYPE} =~ ^(cpu|gpu|java)$ ]]; then | ||
| echo "Internal error: A valid variant type (cpu, gpu, or java) is required. Set VARIANT_TYPE to an appropriate value." | ||
| exit 1 | ||
|
|
@@ -29,8 +31,6 @@ fi | |
| # Validate repo layout using shared script | ||
| ../../scripts/validate_directories_exist.sh "../../../presto" "../../../velox" | ||
|
|
||
| source ./start_presto_helper_parse_args.sh | ||
|
|
||
| COORDINATOR_SERVICE="presto-coordinator" | ||
| COORDINATOR_IMAGE=${COORDINATOR_SERVICE}:latest | ||
| JAVA_WORKER_SERVICE="presto-java-worker" | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -44,48 +44,25 @@ EOF | |
|
|
||
| NUM_THREADS=$(($(nproc) / 2)) | ||
|
|
||
| parse_args() { | ||
| source ../../scripts/helper_functions.sh | ||
| declare -A OPTION_MAP=( ["-b"]="--build-target" ["-j"]="--num-threads" ) | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Changed |
||
| make_options "OPTION_MAP" | ||
|
|
||
| custom_parse_args() { | ||
| while [[ $# -gt 0 ]]; do | ||
| case $1 in | ||
| -h|--help) | ||
| print_help | ||
| exit 0 | ||
| ;; | ||
| -n|--no-cache) | ||
| SKIP_CACHE_ARG="--no-cache" | ||
| shift | ||
| ;; | ||
| -b|--build) | ||
| if [[ -n $2 ]]; then | ||
| BUILD_TARGET=$2 | ||
| shift 2 | ||
| else | ||
| echo "Error: --build requires a value" | ||
| exit 1 | ||
| fi | ||
| ;; | ||
| -j|--num-threads) | ||
| if [[ -n $2 ]]; then | ||
| NUM_THREADS=$2 | ||
| shift 2 | ||
| else | ||
| echo "Error: --num-threads requires a value" | ||
| exit 1 | ||
| fi | ||
| ;; | ||
| *) | ||
| echo "Error: Unknown argument $1" | ||
| print_help | ||
| exit 1 | ||
| ;; | ||
| -h|--help) print_help; exit 0 ;; | ||
| -n|--no-cache) SKIP_CACHE_ARG="--no-cache"; shift ;; | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Left custom in. |
||
| $OPTIONS) parse_option $1 $2; shift 2 ;; | ||
| *) echo "Error: Unknown argument $1"; print_help; exit 1 ;; | ||
| esac | ||
| done | ||
| } | ||
|
|
||
| parse_args "$@" | ||
| custom_parse_args "$@" | ||
|
|
||
| if [[ -n ${BUILD_TARGET} && ! ${BUILD_TARGET} =~ ^(coordinator|c|worker|w|all|a)$ ]]; then | ||
| echo "Error: invalid --build value." | ||
| echo "Error: invalid --build-target value." | ||
| print_help | ||
| exit 1 | ||
| fi | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,79 @@ | ||
| #!/bin/bash | ||
|
|
||
| # Copyright (c) 2025, NVIDIA CORPORATION. | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| shopt -s extglob # needed for paramaterized case statement | ||
|
|
||
| function make_options() { | ||
| local -n LOCAL_OPTION_MAP="$1" | ||
| declare -g OPTIONS="@(" | ||
| SEPARATOR="" | ||
| for key in "${!LOCAL_OPTION_MAP[@]}"; do | ||
| OPTIONS+="${SEPARATOR}$key|${LOCAL_OPTION_MAP[$key]}" | ||
| SEPARATOR="|" | ||
| done | ||
| OPTIONS+=")" | ||
| } | ||
|
|
||
| function make_flags() { | ||
| local -n LOCAL_FLAG_MAP="$1" | ||
| FLAGS="@(" | ||
| SEPARATOR="" | ||
| for key in "${!LOCAL_FLAG_MAP[@]}"; do | ||
| FLAGS+="${SEPARATOR}$key|${LOCAL_FLAG_MAP[$key]}" | ||
| SEPARATOR="|" | ||
| done | ||
| FLAGS+=")" | ||
| } | ||
|
|
||
| function parse_option() { | ||
| local option=$1 | ||
| [[ -v OPTION_MAP["$option"] ]] && option=${OPTION_MAP["$option"]} | ||
| [[ $# -lt 2 || -z $2 ]] && echo "Error: $option requires a value" >&2 && exit 1 | ||
| option=${option//--/} # remove double-dash | ||
| option=${option//-/_} # replace dash with underscore | ||
| option=$(echo "${option^^}") # capitalize | ||
| declare -g "$option=$2" | ||
| } | ||
|
|
||
| function parse_flag() { | ||
| local flag=$1 | ||
| [[ -v FLAG_MAP["$flag"] ]] && flag=${FLAG_MAP["$flag"]} | ||
| flag=${flag//--/} # remove double-dash | ||
| flag=${flag//-/_} # replace dash with underscore | ||
| flag=$(echo "${flag^^}") # capitalize | ||
| declare -g "$flag=true" | ||
| } | ||
|
|
||
| parse_args() { | ||
| while [[ $# -gt 0 ]]; do | ||
| case $1 in | ||
| $OPTIONS) parse_option "$@"; shift 2;; | ||
| $FLAGS) parse_flag $1; shift 1;; | ||
| -h|--help) print_help; exit 0;; | ||
| *) echo "Error: Unknown argument $1"; print_help; exit 1;; | ||
| esac | ||
| done | ||
| } | ||
|
|
||
| parse_args_no_flags() { | ||
| while [[ $# -gt 0 ]]; do | ||
| case $1 in | ||
| $OPTIONS) parse_option "$@"; shift 2;; | ||
| -h|--help) print_help; exit 0;; | ||
| *) echo "Error: Unknown argument $1"; print_help; exit 1;; | ||
| esac | ||
| done | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Left this one in since it sets it's variable to a custom value, rather than "TRUE"