Skip to content

Commit

Permalink
added error checking to update script
Browse files Browse the repository at this point in the history
Signed-off-by: a3hadi <[email protected]>
  • Loading branch information
ayildirim21 committed Mar 6, 2024
1 parent f774280 commit 30850ac
Showing 1 changed file with 28 additions and 6 deletions.
34 changes: 28 additions & 6 deletions update_examples.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ function traverse_examples () {
for command in "$@"
do
if ! $command; then
echo "Error when running $command in $dir"
echo "Error when running $command in $dir" >&2
exit 1
fi
done
Expand All @@ -27,25 +27,34 @@ function traverse_examples () {
done
}

if [ $# -eq 0 ]; then
echo "Error: provide at least one argument" >&2
show_help
exit 1
fi

usingBuild=0
usingSHA=0
usingHelp=0

handle_options() {
while [ $# -gt 0 ]; do
case "$1" in
-h | --help)
show_help
exit 0
usingHelp=1
;;
-b | --build)
traverse_examples "make clean"
usingBuild=1
;;
-c | --commit-sha)
usingSHA=1
if [ -z "$2" ]; then
echo "Commit SHA not specified." >&2
show_help
exit 1
fi

commit_sha=$2
traverse_examples "go get github.com/numaproj/numaflow-go@$commit_sha" "go mod tidy"
shift
;;
*)
Expand All @@ -58,9 +67,22 @@ handle_options() {
done
}

echo "$#"
handle_options "$@"

if (( usingBuild + usingSHA + usingHelp > 1 )); then
echo "Only one of '-h', '-b', '-c' is allowed at a time" >&2
show_help
exit 1
fi

if [ -n "$commit_sha" ]; then
echo "Commit SHA specified: $commit_sha"
fi

if (( usingBuild )); then
traverse_examples "make clean"
elif (( usingSHA )); then
traverse_examples "go get github.com/numaproj/numaflow-go@$commit_sha" "go mod tidy"
elif (( usingHelp )); then
show_help
fi

0 comments on commit 30850ac

Please sign in to comment.