Skip to content

Commit 9705e05

Browse files
author
Lucas Yoon
committed
mend
Signed-off-by: Lucas Yoon <lyoon@lyoon-thinkpadp1gen7.boston.csb>
1 parent 7c1b5d8 commit 9705e05

1 file changed

Lines changed: 64 additions & 0 deletions

File tree

tests/paths_util.sh

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
#!/usr/bin/env bash
2+
3+
# Common variables used by all scripts
4+
stackDirs=''
5+
stacksPath=''
6+
POSITIONAL_ARGS=()
7+
8+
# Function to parse all arguments
9+
parse_arguments() {
10+
while [[ $# -gt 0 ]]; do
11+
case $1 in
12+
--stackDirs)
13+
if [ -z "${stackDirs}" ]; then
14+
stackDirs=$2
15+
else
16+
stackDirs="${stackDirs} $2"
17+
fi
18+
shift # past argument
19+
shift
20+
;;
21+
--stacksPath)
22+
stacksPath=$2
23+
shift # past argument
24+
shift
25+
;;
26+
-*|--*)
27+
# Try script-specific handler if it exists
28+
local consumed=0
29+
local errno=1
30+
if declare -f handle_additional_args > /dev/null 2>&1; then
31+
consumed=$(handle_additional_args "$@")
32+
errno=$?
33+
fi
34+
35+
if [ $errno -eq 0 ] && [ $consumed -gt 0 ]; then
36+
# Script handler consumed some arguments
37+
for ((i=0; i<consumed; i++)); do
38+
shift
39+
done
40+
else
41+
echo "Unknown option $1"
42+
return $errno
43+
fi
44+
;;
45+
*)
46+
POSITIONAL_ARGS+=("$1") # save positional arg
47+
shift # past argument
48+
;;
49+
esac
50+
done
51+
52+
return 0
53+
}
54+
55+
# Function to set default values for stack arguments
56+
set_stack_defaults() {
57+
if [ -z "$stackDirs" ]; then
58+
stackDirs=$(bash "$(pwd)/tests/get_stacks.sh")
59+
fi
60+
61+
if [ -z "$stacksPath" ]; then
62+
stacksPath="$(pwd)/stacks"
63+
fi
64+
}

0 commit comments

Comments
 (0)