# shellcheck shell=dash disable=SC2034,SC2154

# https://gitea.com/api/swagger#/organization/orgGetAll
___x_cmd_fjo_org_ls() {
    param:dsl       '
options:
    --user          "get target user open organization"         <>=""
    --limit         "Results per page"                          <>:Numbers="30"
    --page          "Page number of the results to fetch."      <>:Numbers="1"

    --json|-j       "output origin json data"
    --csv           "output csv data"
    --yml           "output yml data"
'
    param:run

    local _url="/user/orgs"
    [ -z "$user" ] || _url="/users/${user}/orgs"

    if ___x_cmd_gx_output_is_format; then
        ___x_cmd_fjo_get_multi "$_url" | ___x_cmd_gx_output_format
    else
        ___x_cmd_fjo_get_multi "$_url" | \
            x jo 2c            .id .name        | \
            x csv header --add  Id  Name        | \
            if [ -n "$csv" ]; then  ___x_cmd_cmds cat
            else                    x csv static_tab
            fi
    fi

}
