function print_ok() { local msg="${1}" echo "${msg}" }
function print_err() { local msg="${1}" echo "${msg}" > /dev/stderr }
function contain() { local list="${1}" local ele="${2}" for i in ${list[*]}; do if [ "${ele}" == "${i}" ]; then return 0 fi done return 1 }
function check_args_num() { if [ ${args_num} != 1 ]; then print_err "Wrong args num" return 1 fi }
function check_action_arg() { if ! contain "${ALLOWED_ACTION_ARGS[*]}" "${action}"; then print_err "Action arg must be [ set || unset || test ]" return 1 fi }
function unset_proxy() { unset ALL_PROXY print_ok "Unset proxy success" }
function test_proxy() { if curl -k https://www.google.com --connect-timeout 3 >/dev/null 2>&1; then print_ok "Proxy is available" else print_err "Proxy is not available" fi }
if ! check_args_num; then return 1 fi if ! check_action_arg; then return 1 fi
if [ "${action}" == "set" ]; then set_proxy elif [ "${action}" == "unset" ]; then unset_proxy elif [ "${action}" == "test" ]; then test_proxy fi
return $?
1 2 3
source proxy set source proxy unset source proxy test