Skip to content

Commit

Permalink
add --help option and handle unexpected arguments (#182)
Browse files Browse the repository at this point in the history
  • Loading branch information
glennmusa committed Apr 29, 2021
1 parent fb1fbe6 commit d9364d5
Show file tree
Hide file tree
Showing 7 changed files with 137 additions and 39 deletions.
16 changes: 13 additions & 3 deletions src/clean.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ show_help() {
printf "%20s %2s %s \n" "$long_name" "$char_name" "$desc"
}
print_formatted "argument" "" "description"
print_formatted "--mlz-env-name" "-z" "[OPTIONAL] Unique name for MLZ environment (defaults to 'mlz' + UNIX timestamp)"
print_formatted "--mlz-env-name" "-z" "Unique name for MLZ environment"
print_formatted "--help" "-h" "Print this message"
}

usage() {
Expand All @@ -33,14 +34,23 @@ this_script_path=$(realpath "${BASH_SOURCE%/*}")
configuration_output_path="${this_script_path}/generated-configurations"

# check for dependencies

"${this_script_path}/scripts/util/checkforazcli.sh"
"${this_script_path}/scripts/util/checkforterraform.sh"

mlz_env_name="notset"

# inspect user input
while [ $# -gt 0 ] ; do
case $1 in
-z | --mlz-env-name) mlz_env_name="$2" ;;
-z | --mlz-env-name)
shift
mlz_env_name="$1" ;;
-h | --help)
show_help
exit 0 ;;
*)
error_log "ERROR: Unexpected argument: ${1}"
usage && exit 1 ;;
esac
shift
done
Expand Down
41 changes: 32 additions & 9 deletions src/deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,11 @@ show_help() {
print_formatted "--location" "-l" "[OPTIONAL] The location that you're deploying to (defaults to 'eastus')"
print_formatted "--tf-environment" "-e" "[OPTIONAL] Terraform azurerm environment (defaults to 'public') see: https://www.terraform.io/docs/language/settings/backends/azurerm.html#environment"
print_formatted "--mlz-env-name" "-z" "[OPTIONAL] Unique name for MLZ environment (defaults to 'mlz' + UNIX timestamp)"
print_formatted "--hub-sub-id" "-h" "[OPTIONAL] subscription ID for the hub network and resources (defaults to the value provided for -s --subscription-id)"
print_formatted "--hub-sub-id" "-u" "[OPTIONAL] subscription ID for the hub network and resources (defaults to the value provided for -s --subscription-id)"
print_formatted "--tier0-sub-id" "-0" "[OPTIONAL] subscription ID for tier 0 network and resources (defaults to the value provided for -s --subscription-id)"
print_formatted "--tier1-sub-id" "-1" "[OPTIONAL] subscription ID for tier 1 network and resources (defaults to the value provided for -s --subscription-id)"
print_formatted "--tier2-sub-id" "-2" "[OPTIONAL] subscription ID for tier 2 network and resources (defaults to the value provided for -s --subscription-id)"
print_formatted "--help" "-h" "Print this message"
}

usage() {
Expand Down Expand Up @@ -64,14 +65,36 @@ subs_args=()
# inspect user input
while [ $# -gt 0 ] ; do
case $1 in
-s | --subscription-id) mlz_config_subid="$2" ;;
-l | --location) mlz_config_location="$2" ;;
-e | --tf-environment) tf_environment="$2" ;;
-z | --mlz-env-name) mlz_env_name="$2" ;;
-h | --hub-sub-id) subs_args+=("-h ${2}") ;;
-0 | --tier0-sub-id) subs_args+=("-0 ${2}") ;;
-1 | --tier1-sub-id) subs_args+=("-1 ${2}") ;;
-2 | --tier2-sub-id) subs_args+=("-2 ${2}") ;;
-s | --subscription-id)
shift
mlz_config_subid="$1" ;;
-l | --location)
shift
mlz_config_location="$1" ;;
-e | --tf-environment)
shift
tf_environment="$1" ;;
-z | --mlz-env-name)
shift
mlz_env_name="$1" ;;
-u | --hub-sub-id)
shift
subs_args+=("-u ${1}") ;;
-0 | --tier0-sub-id)
shift
subs_args+=("-0 ${1}") ;;
-1 | --tier1-sub-id)
shift
subs_args+=("-1 ${1}") ;;
-2 | --tier2-sub-id)
shift
subs_args+=("-2 ${1}") ;;
-h | --help)
show_help
exit 0 ;;
*)
error_log "ERROR: Unexpected argument: ${1}"
usage && exit 1 ;;
esac
shift
done
Expand Down
4 changes: 2 additions & 2 deletions src/docs/command-line-deployment.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ deploy.sh: create all the configuration and deploy Terraform resources with mini
--location -l [OPTIONAL] The location that you're deploying to (defaults to 'eastus')
--tf-environment -e [OPTIONAL] Terraform azurerm environment (defaults to 'public') see: https://www.terraform.io/docs/language/settings/backends/azurerm.html#environment
--mlz-env-name -z [OPTIONAL] Unique name for MLZ environment (defaults to 'mlz' + UNIX timestamp)
--hub-sub-id -h [OPTIONAL] subscription ID for the hub network and resources (defaults to the value provided for -s --subscription-id)
--hub-sub-id -u [OPTIONAL] subscription ID for the hub network and resources (defaults to the value provided for -s --subscription-id)
--tier0-sub-id -0 [OPTIONAL] subscription ID for tier 0 network and resources (defaults to the value provided for -s --subscription-id)
--tier1-sub-id -1 [OPTIONAL] subscription ID for tier 1 network and resources (defaults to the value provided for -s --subscription-id)
--tier2-sub-id -2 [OPTIONAL] subscription ID for tier 2 network and resources (defaults to the value provided for -s --subscription-id)
Expand All @@ -84,7 +84,7 @@ For example, if I wanted to deploy into four subscriptions (one for each network

```bash
src/deploy.sh -s {my_mlz_configuration_subscription_id} \
-h {my_hub_network_subscription_id} \
-u {my_hub_network_subscription_id} \
-0 {my_identity_network_subscription_id} \
-1 {my_operations_network_subscription_id} \
-2 {my_shared_services_network_subscription_id} \
Expand Down
3 changes: 2 additions & 1 deletion src/docs/ui-deployment.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,12 @@ setup_ezdeploy.sh: Setup the front end for MLZ
--tf-environment -e Terraform azurerm environment (defaults to 'public') see: https://www.terraform.io/docs/language/settings/backends/azurerm.html#environment
--mlz-env-name -z Unique name for MLZ environment (defaults to 'mlz' + UNIX timestamp)
--port -p port to expose the front end web UI on (defaults to '80')
--hub-sub-id -h subscription ID for the hub network and resources (defaults to the value provided for -s --subscription-id)
--hub-sub-id -u subscription ID for the hub network and resources (defaults to the value provided for -s --subscription-id)
--tier0-sub-id -0 subscription ID for tier 0 network and resources (defaults to the value provided for -s --subscription-id)
--tier1-sub-id -1 subscription ID for tier 1 network and resources (defaults to the value provided for -s --subscription-id)
--tier2-sub-id -2 subscription ID for tier 2 network and resources (defaults to the value provided for -s --subscription-id)
--zip-file -f Zipped docker file for use with the 'load' docker strategy (defaults to 'mlz.zip')
--help -h Print this message
```

## Step-by-Step Azure Air Gapped Installation
Expand Down
49 changes: 38 additions & 11 deletions src/scripts/config/generate_config_file.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,11 @@ show_help() {
print_formatted "--location" "-l" "The location that you're deploying to (e.g. 'eastus')"
print_formatted "--config-sub-id" "-s" "Subscription ID for MissionLZ configuration resources"
print_formatted "--tenant-id" "-t" "Tenant ID where your subscriptions live"
print_formatted "--hub-sub-id" "-h" "[OPTIONAL]: subscription ID for the hub network and resources"
print_formatted "--hub-sub-id" "-u" "[OPTIONAL]: subscription ID for the hub network and resources"
print_formatted "--tier0-sub-id" "-0" "[OPTIONAL]: subscription ID for tier 0 network and resources"
print_formatted "--tier1-sub-id" "-1" "[OPTIONAL]: subscription ID for tier 1 network and resources"
print_formatted "--tier2-sub-id" "-2" "[OPTIONAL]: subscription ID for tier 2 network and resources"
print_formatted "--help" "-h" "Print this message"
}

usage() {
Expand All @@ -49,16 +50,42 @@ mlz_tenant_id="notset"
# inspect arguments
while [ $# -gt 0 ] ; do
case $1 in
-f | --file) dest_file="$2" ;;
-e | --tf-env) tf_environment="$2" ;;
-z | --mlz-env-name) mlz_env_name="$2" ;;
-l | --location) mlz_config_location="$2" ;;
-s | --config-sub-id) mlz_config_subid="$2" ;;
-t | --tenant-id) mlz_tenant_id="$2" ;;
-h | --hub-sub-id) mlz_saca_subid="$2" ;;
-0 | --tier0-sub-id) mlz_tier0_subid="$2" ;;
-1 | --tier1-sub-id) mlz_tier1_subid="$2" ;;
-2 | --tier2-sub-id) mlz_tier2_subid="$2" ;;
-f | --file)
shift
dest_file="$1" ;;
-e | --tf-env)
shift
tf_environment="$1" ;;
-z | --mlz-env-name)
shift
mlz_env_name="$1" ;;
-l | --location)
shift
mlz_config_location="$1" ;;
-s | --config-sub-id)
shift
mlz_config_subid="$1" ;;
-t | --tenant-id)
shift
mlz_tenant_id="$1" ;;
-u | --hub-sub-id)
shift
mlz_saca_subid="$1" ;;
-0 | --tier0-sub-id)
shift
mlz_tier0_subid="$1" ;;
-1 | --tier1-sub-id)
shift
mlz_tier1_subid="$1" ;;
-2 | --tier2-sub-id)
shift
mlz_tier2_subid="$1" ;;
-h | --help)
show_help
exit 0 ;;
*)
error_log "ERROR: Unexpected argument: ${1}"
usage && exit 1 ;;
esac
shift
done
Expand Down
13 changes: 11 additions & 2 deletions src/scripts/export_docker.sh
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
# SC1091: Not following. Shellcheck can't follow non-constant source.
# SC2154: "var is referenced but not assigned". These values come from an external file.
#
# This script locally saves a local docker image for movement between airgapped networks.
# This script locally saves a local docker image for movement between airgapped networks.

set -e

Expand All @@ -26,6 +26,7 @@ show_help() {
}
print_formatted "argument" "" "description"
print_formatted "--output-file" "-f" "Output file name/location, defaults to same directory 'mlz.zip'"
print_formatted "--help" "-h" "Print this message"
}

usage() {
Expand All @@ -39,7 +40,15 @@ zip_file="mlz.zip"
# inspect user input
while [ $# -gt 0 ] ; do
case $1 in
-f | --output-file) zip_file="$2" ;;
-f | --output-file)
shift
zip_file="$1" ;;
-h | --help)
show_help
exit 0 ;;
*)
error_log "ERROR: Unexpected argument: ${1}"
usage && exit 1 ;;
esac
shift
done
Expand Down
50 changes: 39 additions & 11 deletions src/scripts/setup_ezdeploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ show_help() {
print_formatted "--tier1-sub-id" "-1" "subscription ID for tier 1 network and resources (defaults to the value provided for -s --subscription-id)"
print_formatted "--tier2-sub-id" "-2" "subscription ID for tier 2 network and resources (defaults to the value provided for -s --subscription-id)"
print_formatted "--zip-file" "-f" "Zipped docker file for use with the 'load' docker strategy (defaults to 'mlz.zip')"
print_formatted "--help" "-h" "Print this message"
}

usage() {
Expand Down Expand Up @@ -64,17 +65,44 @@ subs_args=()
# inspect user input
while [ $# -gt 0 ] ; do
case $1 in
-d | --docker-strategy) docker_strategy="$2" ;;
-s | --subscription-id) mlz_config_subid="$2" ;;
-l | --location) mlz_config_location="$2" ;;
-e | --tf-environment) tf_environment="$2" ;;
-z | --mlz-env-name) mlz_env_name="$2" ;;
-p | --port) web_port="$2" ;;
-h | --hub-sub-id) subs_args+=("-h ${2}") ;;
-0 | --tier0-sub-id) subs_args+=("-0 ${2}") ;;
-1 | --tier1-sub-id) subs_args+=("-1 ${2}") ;;
-2 | --tier2-sub-id) subs_args+=("-2 ${2}") ;;
-f | --zip-file) zip_file="$2" ;;
-d | --docker-strategy)
shift
docker_strategy="$1" ;;
-s | --subscription-id)
shift
mlz_config_subid="$1" ;;
-l | --location)
shift
mlz_config_location="$1" ;;
-e | --tf-environment)
shift
tf_environment="$1" ;;
-z | --mlz-env-name)
shift
mlz_env_name="$1" ;;
-p | --port)
shift
web_port="$1" ;;
-u | --hub-sub-id)
shift
subs_args+=("-u ${1}") ;;
-0 | --tier0-sub-id)
shift
subs_args+=("-0 ${1}") ;;
-1 | --tier1-sub-id)
subs_args+=("-1 ${1}") ;;
-2 | --tier2-sub-id)
shift
subs_args+=("-2 ${1}") ;;
-f | --zip-file)
shift
zip_file="$1" ;;
-h | --help)
show_help
exit 0 ;;
*)
error_log "ERROR: Unexpected argument: ${1}"
usage && exit 1 ;;
esac
shift
done
Expand Down

0 comments on commit d9364d5

Please sign in to comment.