-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
234 additions
and
104 deletions.
There are no files selected for viewing
34 changes: 34 additions & 0 deletions
34
src/main/resources/io/viash/helpers/bashutils/ViashParseArgumentValue.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
function ViashParseArgumentValue { | ||
local env_name="$1" | ||
local multiple="$2" | ||
local flag="$3" | ||
local value="$4" | ||
|
||
if [ $# -lt 4 ]; then | ||
ViashError "Not enough arguments passed to ${flag}. Use '--help' to get more information on the parameters." | ||
exit 1 | ||
fi | ||
|
||
if [ "$multiple" == "false" ]; then | ||
# check whether the variable is already set | ||
if [ ! -z ${!env_name+x} ]; then | ||
local -n prev_value="$env_name" | ||
ViashError "Pass only one argument to argument '${flag}'. Found: ${prev_value@Q} & ${value@Q}" | ||
exit 1 | ||
fi | ||
|
||
# set the variable | ||
declare -g "$env_name=${value}" | ||
else | ||
local new_values | ||
|
||
local -n prev_values="$env_name" | ||
|
||
# todo: allow escaping the delimiter | ||
readarray -d ';' -t new_values < <(printf '%s' "$value") | ||
|
||
combined_values=( "${prev_values[@]}" "${new_values[@]}" ) | ||
|
||
declare -g -a "$env_name=(\"\${combined_values[@]}\")" | ||
fi | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.