# shellcheck shell=dash

___x_cmd_gcode_user_repo(){
    param:subcmd ___x_cmd_gcode_user_repo    \
        ls          "list user repo"
    param:subcmd:try
    param:run

    ___x_cmd_gcode_user_repo _param_help_doc
    return 1
}

# Section: List
# http://localhost:4000/13.7/ee/api/projects.html#list-user-projects
# shellcheck disable=2034
___x_cmd_gcode_user_repo_ls(){
    param:scope     ___x_cmd_gcode
    param:dsl       '
options:
    #1              "user path (default the authenticated user)"                <>=""
    --page          "page"                                                      <>:Per_page="1"
    --per_page      "per_page"                                                  <>:Numbers="30"
    --visibility    "Limit by repo visibility"                                  <>=""       = private public internal ""
    --owned         "Limit by projects explicitly owned by the current user"
    --json|-j       "output json data"
'
    param:run
    local _url=""
    if [ -n "$1" ]; then
        _url="/users/$1/projects"
    else
        _url="/projects"
        owned=true
    fi

    if [ -n "$json" ] || [ -n "$ENFORCE_JSON" ]; then
        ___x_cmd_gcode_get_multi "$_url" visibility owned
    else
        ___x_cmd_gcode_get_multi "$_url" visibility owned | \
            x jo 2c             .id      .path_with_namespace .visibility .default_branch .description | \
            x csv header --add   Repo_ID  Owner_Porject        Visibility  Default_Branch  Description | \
            x csv static_tab
    fi
}

# EndSection
