# Author:       Li Junhao   l@x-cmd.com             # xrc
# shellcheck    shell=sh    disable=SC2039,SC3043
x log init http

xrc param
xrc dict
xrc:mod:lib http  utils header qs body request resp crud/index

___x_cmd_http() {
    local O="${O:-_HTTP_DEFAULT}"
    if [ "${1#@}" != "$1" ]; then
        O="${1#@}"
        shift
    fi
    # TODO: 直接调用内部函数会出问题，需要在调用的时候给O加上___X_BASH_HTTP_
    O="___X_BASH_HTTP_${O}"
    param:advise http
    param:subcmd ___x_cmd_http                                              \
        get             "launch a get request"                              \
        download        "download file"                                     \
        rget            "launch a get request and follow 3xx redirection"   \
        post            "launch a post request"                             \
        put             "launch a put request"                              \
        patch           "launch a patch request"                            \
        delete          "launch a delete request"                           \
        resp            "get resp data"                                     \
        head            "launch a head request"                             \
        header          "set the default header"                            \
        body            "set the default attribute in body"                 \
        qs              "set the default query string parameter"            \
        browse          "open browser"                                      \
        make            "make a new client"                                 \
        cd              "enter into the subpath relative to current path"
    param:subcmd:try
    param:run

    # response        "get the response information of latest request"    \
    # graphql|gq      "launch a graphql request"                          \
    ___x_cmd_http _param_help_doc
    return 1
}

xrc setmain ___x_cmd_http
