Skip to content

Commit

Permalink
support flags (#92)
Browse files Browse the repository at this point in the history
  • Loading branch information
autero1 authored Apr 24, 2024
1 parent afedd68 commit 67d6b51
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 3 deletions.
10 changes: 7 additions & 3 deletions gruntwork-install
Original file line number Diff line number Diff line change
Expand Up @@ -310,9 +310,13 @@ function install_script_module {
shift
;;
--module-param)
local module_param_key="${2%%=*}"
local module_param_val="${2#*=}"
module_params+=( "--$module_param_key" "$module_param_val" )
if [[ $2 == *"="* ]]; then
local module_param_key="${2%%=*}"
local module_param_val="${2#*=}"
module_params+=( "--$module_param_key" "$module_param_val" )
else
module_params+=( "--$2" )
fi
shift
;;
--download-dir)
Expand Down
3 changes: 3 additions & 0 deletions modules/mixed-args-module/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Mixed args module

This module is used solely for running automated tests against the Gruntwork Installer.
44 changes: 44 additions & 0 deletions modules/mixed-args-module/install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#!/bin/bash
# A dirt simple install script that expects one madatory argument, --message-to-echo, that it echoes. The echo message can be overridden with
# a flag, --echo-override. This is used to test that the --module-param args in gruntwork-install can handle flags without values.

set -e

function assert_not_empty {
local -r arg_name="$1"
local -r arg_value="$2"

if [[ -z "$arg_value" ]]; then
echo "ERROR: The value for '$arg_name' cannot be empty"
exit 1
fi
}

function install {
local echomessage

while [[ $# > 0 ]]; do
local key="$1"

case "$key" in
--message-to-echo)
echomessage="$2"
shift
;;
--echo-override)
echomessage="Override"
;;
*)
echo "Unrecognized argument: $key"
exit 1
;;
esac

shift
done

assert_not_empty "--message-to-echo" "$echomessage"
echo "$echomessage"
}

install "$@"
3 changes: 3 additions & 0 deletions test/integration-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ configure-ecs-instance --help
echo "Using gruntwork-install to install a module from the gruntwork-install repo and passing args to it via --module-param"
gruntwork-install --module-name "dummy-module" --repo "https://github.com/gruntwork-io/gruntwork-installer" --tag "v0.0.25" --module-param "file-to-cat=$SCRIPT_DIR/integration-test.sh"

echo "Using gruntwork-install to install a module from the gruntwork-install repo and passing mixed args to it via --module-param"
gruntwork-install --module-name "mixed-args-module" --repo "https://github.com/gruntwork-io/gruntwork-installer" --ref "fix/mixed-args" --module-param "message-to-echo=Hello" --module-param "echo-override"

echo "Using gruntwork-install to install a module from the gruntwork-install repo with branch as ref"
gruntwork-install --module-name "dummy-module" --repo "https://github.com/gruntwork-io/gruntwork-installer" --ref "for-testing-dont-delete" --module-param "file-to-cat=$SCRIPT_DIR/integration-test.sh"

Expand Down

0 comments on commit 67d6b51

Please sign in to comment.