_goldcrest_completion()
{
    local compopt current prev optlist

    current="${COMP_WORDS[$COMP_CWORD]}"

    prev="${COMP_WORDS[$COMP_CWORD - 1]}"

    compopt=""

    optlist="--air-4to6 -n \
             --air-6to4 -B \
             --air-black-country-list -X \
             --air-black-server-list -M \
             --air-connect -O \
             --air-country -Z \
             --air-info -I \
             --air-ipv6 -V \
             --air-key -F \
             --air-key-list -K \
             --air-key-load -Q \
             --air-list -L \
             --air-sort \
             --air-limit \
             --air-password -P \
             --air-save -W \
             --air-server -S \
             --air-tls-mode -T \
             --air-user -U \
             --air-user-info \
             --air-vpn-type -f \
             --air-white-country-list -J \
             --air-white-server-list -G \
             --air-bootserver-info \
             --async \
             --allowuaf -6 \
             --alt-proxy -A \
             --auth-retry -Y \
             --auto-sess -a \
             --bluetit-stats \
             --bluetit-status \
             --cipher -C \
             --compress -c \
             --def-keydir -k \
             --disconnect \
             --epki-ca \
             --epki-cert \
             --epki-key \
             --gremlin -g \
             --gui-version -E \
             --help -h \
             --ignore-dns-push -i \
             --list-data-ciphers -D \
             --mtu -r \
             --network-lock -N \
             --allow-private-network \
             --allow-ping \
             --allow-ipv6ndp \
             --no-cert -x \
             --pause \
             --peer-info -e \
             --persist-tun -j \
             --pk-password -z \
             --port -R \
             --proto -p \
             --proxy-basic -b \
             --proxy-host -y \
             --proxy-password -w \
             --proxy-port -q \
             --proxy-username -u \
             --reconnect \
             --recover-network -H \
             --remove-wireguard-device \
             --resume \
             --server -s \
             --ssl-debug \
             --tcp-queue-limit -l \
             --tcprof-override -o \
             --timeout -t \
             --tvm-override -m \
             --version -v"

    if [[ "${current}" =~ ^- ]]; then
        compopt=$optlist
    else
        case "${prev}" in
            --air-4to6|-n)
                compopt="on off"
                ;;

            --air-6to4|-B)
                compopt="on off"
                ;;

            --air-black-country-list|-X)
                compopt="country_list"
                ;;

            --air-black-server-list|-M)
                compopt="server_list"
                ;;

            --air-connect|-O)
                compopt=""
                ;;

            --air-country|-Z)
                compopt="country_pattern country_ISO_code continent_code"
                ;;

            --air-info|-I)
                compopt="--air-server --air-country"
                ;;

            --air-ipv6|-V)
                compopt="on off"
                ;;

            --air-key|-F)
                compopt="key_name"
                ;;

            --air-key-list|-K)
                compopt=""
                ;;

            --air-key-load|-Q)
                compopt=$(compgen -f)
                ;;

            --air-list|-L)
                compopt="server_or_country_pattern"
                ;;

            --air-sort)
                compopt="name location score load users bandwidth maxbandwidth"
                ;;

            --air-limit)
                compopt="number"
                ;;

            --air-password|-P)
                compopt="password"
                ;;

            --air-save|-W)
                compopt=$(compgen -f)
                ;;

            --air-server|-S)
                compopt="server_pattern"
                ;;

            --air-tls-mode|-T)
                compopt="auto auth crypt"
                ;;

            --air-user|-U)
                compopt="username"
                ;;

            --air-user-info)
                compopt=""
                ;;

            --air-vpn-type|-f)
                compopt="wireguard openvpn"
                ;;

            --air-white-country-list|-J)
                compopt="country_list"
                ;;

            --air-white-server-list|-G)
                compopt="server_list"
                ;;

            --air-booserver-info)
                compopt=""
                ;;

            --allowuaf|-6)
                compopt="yes no default"
                ;;

            --async)
                compopt=""
                ;;

            --alt-proxy|-A)
                compopt=""
                ;;

            --auth-retry|-Y)
                compopt=""
                ;;

            --auto-sess|-a)
                compopt=""
                ;;

            --bluetit-stats)
                compopt=""
                ;;

            --bluetit-status)
                compopt=""
                ;;

            --cipher|-C)
                compopt="AES-128-GCM AES-192-GCM AES-256-GCM CHACHA20-POLY1305"
                ;;

            --compress|-c)
                compopt="yes no asym"
                ;;

            --def-keydir|-k)
                compopt="bi 0 1"
                ;;

            --disconnect)
                compopt=""
                ;;

            --epki-ca)
                compopt="ca"
                ;;

            --epki-cert)
                compopt="cert"
                ;;

            --epki-key)
                compopt="key"
                ;;

            --gremlin|-g)
                compopt="send_delay_ms recv_delay_ms send_drop_prob recv_drop_prob"
                ;;

            --gui-version|-E)
                compopt="text"
                ;;

            --help|-h)
                compopt=""
                ;;

            --ignore-dns-push|-i)
                compopt=""
                ;;

            --list-data-ciphers|-D)
                compopt=""
                ;;

            --mtu|-r)
                compopt="mtu_value"
                ;;

            --network-lock|-N)
                compopt="on iptables nftables pf off noprivate"
                ;;

            --allow-private-network)
                compopt="on off"
                ;;

            --allow-ping)
                compopt="on off input output"
                ;;

            --allow-ipv6ndp)
                compopt="on off"
                ;;

            --no-cert|-x)
                compopt=""
                ;;

            --pause)
                compopt=""
                ;;

            --peer-info|-e)
                compopt=""
                ;;

            --persist-tun|-j)
                compopt=""
                ;;

            --pk-password|-z)
                compopt="password"
                ;;

            --port|-R)
                compopt="port_number"
                ;;

            --proto|-p)
                compopt="tcp udp"
                ;;

            --proxy-basic|-b)
                compopt=""
                ;;

            --proxy-host|-y)
                compopt="hostname ip_address"
                ;;

            --proxy-port|-q)
                compopt="port_number"
                ;;

            --port|-R)
                compopt="port_number"
                ;;

            --proxy-username|-u)
                compopt="username"
                ;;

            --reconnect)
                compopt=""
                ;;

            --recover-network|-H)
                compopt=""
                ;;

            --remove-wireguard-device)
                compopt=""
                ;;

            --resume)
                compopt=""
                ;;

            --server|-s)
                compopt="server_host server_ip"
                ;;

            --ssl-debug)
                compopt="value"
                ;;

            --tcp-queue-limit|-l)
                compopt="value"
                ;;

            --tcprof-override|-o)
                compopt="legacy preferred ..."
                ;;

            --timeout|-t)
                compopt="seconds"
                ;;

            --tvm-override|-m)
                compopt="disabled default tls_1_x"
                ;;

            --version|-v)
                compopt=""
                ;;

            *)
                compopt=$(compgen -f)
                ;;
        esac
    fi

    if [ "${compopt}" == "" ]; then
        compopt=$(compgen -f)
    fi

    COMPREPLY=($(compgen -W "${compopt}" -- ${current}))

    return 0
}

complete -F _goldcrest_completion goldcrest
