diff --git a/scripts/bin/hosto b/scripts/bin/hosto index b4a712b..e93c5e9 100755 --- a/scripts/bin/hosto +++ b/scripts/bin/hosto @@ -1,5 +1,20 @@ #!/usr/bin/env bash + +function help() { + echo -e \ + "Usage: $(basename $0) [OPTIONS]\n\n" \ + "Options:\n" \ + " -i, --inv-file Specify the Ansible inventory to add.\n" \ + " -h, --help Show help.\n" +} + +if [[ $# -eq 0 ]]; then + help + exit 1 +fi + + POSITIONAL_ARGS=() INVENTORY_FILE="$(pwd)/inventory" @@ -10,8 +25,8 @@ while [[ $# -gt 0 ]]; do shift shift ;; - -*|--*) - echo "hosto: Unknown option $1" + -h|--help) + help exit 1 ;; *) @@ -22,10 +37,10 @@ while [[ $# -gt 0 ]]; do done if [ -f $INVENTORY_FILE ]; then - sudo inv-alias add $INVENTORY_FILE - eval "${POSITIONAL_ARGS[@]}" - sudo inv-alias rm $INVENTORY_FILE + sudo inv-alias add $INVENTORY_FILE + eval "${POSITIONAL_ARGS[@]}" + sudo inv-alias rm $INVENTORY_FILE else - echo "hosto: Could not find inventory file at $INVENTORY_FILE" - eval "${POSITIONAL_ARGS[@]}" + echo "hosto: Could not find inventory file at $INVENTORY_FILE" + eval "${POSITIONAL_ARGS[@]}" fi