# shellcheck shell=sh disable=SC3043,SC2276,SC2289,SC2154

# author:       Li Junhao           l@x-cmd.com    edwinjhlee.github.io
# maintainer:   Li Junhao

___x_cmd log init proxy

alias proxy:local:init='
    local http_proxy=""
    local https_proxy=""
    local ftp_proxy=""
    local all_proxy=""
    local HTTP_PROXY=""
    local HTTPS_PROXY=""
    local FTP_PROXY=""
    local ALL_PROXY=""
'

alias proxy:local='
    local http_proxy="$http_proxy"
    local https_proxy="$https_proxy"
    local ftp_proxy="$ftp_proxy"
    local all_proxy="$all_proxy"
    local HTTP_PROXY="$HTTP_PROXY"
    local HTTPS_PROXY="$HTTPS_PROXY"
    local FTP_PROXY="$FTP_PROXY"
    local ALL_PROXY="$ALL_PROXY"
'

xrc:mod:lib     proxy       __str normalize ls __seti unset wrap

___x_cmd_proxy___main(){
    [ "$#" -gt 0 ] ||   set -- --help

    local op="$1"; shift
    case "$op" in
        ls|set|unset|wrap|run|normalize|runifset)
            ___x_cmd_proxy_"$op" "$@" ;;
        -h|--help)
            ___x_cmd help -m proxy "$@"
            return   ;;
        *)  
            N=proxy M="subcommand not found." log:ret:1 ;;
    esac
}

___x_cmd_proxy_run(){
    proxy:local:init
    local ___X_CMD_PROXY_SET_RUN_ENABLED=1
    ___x_cmd_proxy___seti "$@"
}

___x_cmd_proxy_runifset(){
    local p="$1"
    if [ -z "$p" ]; then
        shift
        [ "$1" != -- ]    ||    shift
        "$@"
    else
        ___x_cmd_proxy_run "$@"
    fi
}

___x_cmd_proxy_set(){
    local ___X_CMD_PROXY_SET_RUN_ENABLED=
    ___x_cmd_proxy___seti "$@"
    
    ___x_cmd_proxy___xbinexp
}

___x_cmd_proxy___xbinexp(){
    [ -n "$___X_CMD_XBINEXP_FP" ] || return 0
    ___x_cmd_xbinexp___add http_proxy https_proxy ftp_proxy all_proxy HTTP_PROXY HTTPS_PROXY FTP_PROXY ALL_PROXY
}



