Skip to content

Commit

Permalink
scripts: move contains helper to common library
Browse files Browse the repository at this point in the history
  • Loading branch information
alexandre-allard committed Feb 3, 2021
1 parent a7d4876 commit 8c8bb82
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
11 changes: 11 additions & 0 deletions scripts/common.sh.in
Original file line number Diff line number Diff line change
Expand Up @@ -410,3 +410,14 @@ join() {
printf "$sep%s" "${elements[@]:1}"
fi
}

# helper function to check for element in array
contains() {
local -r match=$1; shift

for element; do
[[ "$element" == "$match" ]] && return
done

return 1
}
12 changes: 1 addition & 11 deletions scripts/iso-manager.sh
Original file line number Diff line number Diff line change
Expand Up @@ -79,16 +79,6 @@ _set_env() {
fi
}

# helper function to check for element in array
containsElement () {
local element match="$1"
shift
for element in "$@"; do
[[ "$element" == "$match" ]] && return 0;
done
return 1
}

_add_archives() {
# Skip adding archive if None passed
[ $# -lt 1 ] && return 0
Expand All @@ -101,7 +91,7 @@ _add_archives() {
archives <<< "$(salt-call pillar.get metalk8s:archives \
--out txt | cut -d' ' -f2- | tr -d '[],')"
for archive in "$@"; do
if ! containsElement "'$archive'" "${archives[@]}"; then
if ! contains "$archive" "${archives[@]}"; then
archives+=("'$archive'")
fi
done
Expand Down

0 comments on commit 8c8bb82

Please sign in to comment.