# shellcheck shell=dash

___x_cmd_luarocks___xmirror(){
    [ $# -gt 0 ] || set - current

    local op="$1";  shift
    case "$op" in
        -h|--help)             ___x_cmd help -m luarocks mirror                ;;
        ls|current|set|reset)  ___x_cmd_luarocks___xmirror_"$op"   "$@" ;;
    esac
}

___x_cmd_luarocks___xmirror_ls(){
    printf "%s\n" \
        "Code          Url                             Name" \
        "cn            https://luarocks.cn             支流科技" \
        "official      https://luarocks.org            Official"
}

___x_cmd_luarocks___xmirror_current(){
    # [ -f "$HOME/.luarocks/config.lua" ] || printf "%s\n" "https://luarocks.org"
    ___x_cmd luarocks config rocks_servers
}

___x_cmd_luarocks___xmirror_set(){
    # TODO: delete the code with ' x-cmd '
    # x luarocks install <rock> --server https://luarocks.cn

    local site="https://luarocks.org"
    case "$1" in
        --official) ;;
        --cn)       site="https://luarocks.cn" ;;
    esac

    # local data='rocks_servers = {  "'$site'"; } # x-cmd luarock mirror'
    # printf "%s\n" "$data" > "$HOME/.luarocks/config.lua"

    # TODO: currently not using mirror for rock upload. We will consider it later.
}

___x_cmd_luarocks___xmirror_reset(){
    ___x_cmd_luarocks___xmirror_set --official
}
