Skip to content

Commit 181cb64

Browse files
committed
added argument parsing and help text
1 parent 8eb03b6 commit 181cb64

File tree

1 file changed

+30
-7
lines changed

1 file changed

+30
-7
lines changed

gitfile.sh

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,21 @@
22

33
set -euo pipefail
44

5+
function printHelpText
6+
{
7+
echo "Usage:"
8+
echo " ${0} [OPTIONS]"
9+
echo ""
10+
echo "application Options:"
11+
echo " -p, --default-clone-path= Default path to git clone into (default: ./)"
12+
echo " -f, --gitfile= File path to the Gitfile (default: ./gitfile)"
13+
echo ""
14+
echo "Help Options:"
15+
echo " -h, --help Show this help message and exit"
16+
echo ""
17+
exit 0
18+
}
19+
520
function cloneRepo
621
{
722
SOURCE=${1}
@@ -46,15 +61,23 @@ function parseYaml
4661
}
4762

4863
DEFAULT_GIT_CLONE_PATH="."
49-
if [ "$#" -eq 1 ]; then
50-
DEFAULT_GIT_CLONE_PATH=${1%/}
51-
fi
64+
YAML_FILE="./.gitfile"
65+
while [ "$#" -gt 0 ]; do
66+
case "$1" in
67+
-p) DEFAULT_GIT_CLONE_PATH="${2%/}"; shift 2;;
68+
-f) YAML_FILE="$2"; shift 2;;
5269

70+
--default-clone-path=*) DEFAULT_GIT_CLONE_PATH="${1#*=}"; shift 1;;
71+
--gitfile=*) YAML_FILE="${1#*=}"; shift 1;;
72+
--default-clone-path|--gitfile) echo "$1 requires an argument" >&2; exit 1;;
5373

54-
YAML_FILE="./.gitfile"
55-
if [ "$#" -eq 2 ]; then
56-
YAML_FILE="${2}"
57-
fi
74+
-h) printHelpText;;
75+
--help) printHelpText;;
76+
77+
-*) echo "unknown option: $1" >&2; exit 1;;
78+
*) handle_argument "$1"; shift 1;;
79+
esac
80+
done
5881

5982
if [ ! -f "${YAML_FILE}" ]; then
6083
echo "[ERROR] '${YAML_FILE}' does not exist"

0 commit comments

Comments
 (0)