Skip to content

Commit

Permalink
Fix how params are passed so we can handle spaces in param values
Browse files Browse the repository at this point in the history
  • Loading branch information
brikis98 committed May 18, 2016
1 parent f6661be commit c1c5673
Showing 1 changed file with 10 additions and 20 deletions.
30 changes: 10 additions & 20 deletions gruntwork-install
Original file line number Diff line number Diff line change
Expand Up @@ -97,32 +97,22 @@ function validate_module {
fi
}

# Take in an array of key-val pairs in this format:
# module_params[0] = "key1=value1"
# module_params[1] = "key2=value2"
# .. and convert it to the format that Gruntwork bash scripts expect:
# --key1 value1 --key2 value2
# Take in a key-value pair of the format key=value and convert it to the format that Gruntwork bash scripts expect:
# --key value
function convert_module_params_format {
local readonly module_params=("${@}")

module_params_formatted=""
for key_val_expression in "${module_params[@]}"; do
key="${key_val_expression%=*}"
val="${key_val_expression#*=}"
module_params_formatted="--${key} ${val} ${module_params_formatted}"
done

echo $module_params_formatted
local readonly key_value_pair="$1"
local readonly key="${key_value_pair%%=*}"
local readonly val="${key_value_pair#*=}"
echo "--${key} '${val}'"
}

function run_module {
local readonly module_name="$1"
shift
local readonly module_params=($@)
local readonly module_params_formatted=$(convert_module_params_format "${module_params[@]}")
local readonly module_params="$@"

chmod -R u+x "${MODULES_DOWNLOAD_DIR}/${module_name}"
eval "${MODULES_DOWNLOAD_DIR}/${module_name}/${MODULE_INSTALL_FILE_NAME} ${module_params_formatted}"
${MODULES_DOWNLOAD_DIR}/${module_name}/${MODULE_INSTALL_FILE_NAME} $module_params
}

function install_script_module {
Expand All @@ -148,8 +138,8 @@ function install_script_module {
shift
;;
--module-param)
module_param="$2"
module_params+=("$module_param")
local readonly param=$(convert_module_params_format "$2")
module_params+=("$param")
shift
;;
--help)
Expand Down

0 comments on commit c1c5673

Please sign in to comment.