Skip to content

Commit

Permalink
Merge pull request #43 from jasonkarns/inspect-args
Browse files Browse the repository at this point in the history
inspect args
  • Loading branch information
jasonkarns authored Jun 4, 2024
2 parents 41ac2c3 + bc34127 commit 7d95208
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions binstub
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,26 @@ eval "${_STUB_INDEX}"=1
eval "${_STUB_RESULT}"=0
[ ! -e "${!_STUB_RUN}" ] || source "${!_STUB_RUN}"

# Expose this for stub scripts.
inspect_args() {
local arg
local sep=''
for arg; do
if [[ $arg == *' '* ]]; then
printf '%s"%s"' "$sep" "${arg//\"/\\\"}"
elif [[ $arg == *'"'* ]]; then
printf "%s'%s'" "$sep" "$arg"
else
printf '%s%s' "$sep" "$arg"
fi
sep=" "
done
}

# Loop over each line in the plan.
IFS=$'\n' read -d '' -r -a lines < "${!_STUB_PLAN}" || true
index=0
while IFS= read -r line; do
for line in "${lines[@]}"; do
index=$(($index + 1))

if [[ -z "${!_STUB_END}" && -n "${!_STUB_NOINDEX}" || $index -eq "${!_STUB_INDEX}" ]]; then
Expand Down Expand Up @@ -77,7 +93,7 @@ while IFS= read -r line; do
eval "${_STUB_RESULT}"=1
fi
fi
done < "${!_STUB_PLAN}"
done


if [ -n "${!_STUB_END}" ]; then
Expand Down

0 comments on commit 7d95208

Please sign in to comment.