Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 26 additions & 7 deletions bin/proxy
Original file line number Diff line number Diff line change
Expand Up @@ -141,23 +141,42 @@ function pick_one_virtual_host_from_file() {
local EXCEPT=$2

local HOST_STRING
local HOSTS
local HOSTS=()
local HOST
local HOST_OPTIONS=()

HOST_STRING=$(sed -nr 's/.*VIRTUAL_HOST=(.*)/\1/p' "$FILE")

IFS="," read -ra HOSTS <<< "$HOST_STRING"

for HOST_ENTRY in "${HOSTS[@]}"; do
if [ "$HOST_ENTRY" != "$EXCEPT" ]; then
HOST=$HOST_ENTRY
break;
fi
if [ "$HOST_ENTRY" != "$EXCEPT" ]; then
HOST_OPTIONS+=("$HOST_ENTRY")
fi
done

if [ -z "$HOST" ]; then
output_error "No VIRTUAL_HOST found in $FILE."
if [ "${#HOST_OPTIONS[@]}" -eq "0" ]; then
output_error "No VIRTUAL_HOST overrides found in $FILE."
exit 1
elif [ "${#HOST_OPTIONS[@]}" -gt "1" ]; then
PS3="Select a Proxy URL (or quit to exit): "
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wording threw me off a little. "or type quit to exit" might be a little more clear

while [ -z "$HOST" ]; do
select opt in "${HOST_OPTIONS[@]}"; do
if [ -z "$opt" ]; then
if [ "$REPLY" == "quit" ]; then
output_info "Exiting..."
exit 1
fi
>&2 output_error "Invalid selection: $REPLY. Please enter the number of the option you wish to select."
continue
fi

HOST=$opt
break
done
done
else
HOST=${HOST_OPTIONS[0]}
fi

echo "$HOST"
Expand Down