I have this contains function which is supposed to check if an array has a certain value. The array itself is passed as the 1st arg, and the value is the 2nd arg.
#!/usr/bin/env bash
set -e;
branch_type="${1:-feature}";
arr=( 'feature', 'bugfix', 'release' );
contains() {
local array="$1"
local seeking="$2"
echo "seeking => $seeking";
# for v in "${!array}"; do
for v in "${array[@]}"; do
echo "v is $v";
if [ "$v" == "$seeking" ]; then
echo "v is seeking";
return 0;
fi
done
echo "returning with 1";
return 1;
}
if ! contains "$arr" "$branch_type"; then
echo "Branch type needs to be either 'feature', 'bugfix' or 'release'."
echo "The branch type you passed was: $branch_type"
exit 1;
fi
echo "all goode. branch type is $branch_type";
if you run the script without any args, it should work, since the default is "feature", but for some reason, the search is not matching anything. I am not getting an error, but the contains functions is not working as desired.
When I run the script w/o any arguments, I get:
seeking => feature
v is feature,
returning with 1
Branch type needs to be either 'feature', 'bugfix' or 'release'.
The branch type you passed was: feature
now that's weird