# shellcheck shell=dash

___x_cmd_fjo_search(){
    param:scope  ___x_cmd_fjo
    param:subcmd ___x_cmd_fjo_search     \
        "repo"       "search repo"
    param:subcmd:try
    param:run

    ___x_cmd_fjo_search _param_help_doc
    return 1
}
# https://codeberg.org/api/swagger#/repository/repoSearch
___x_cmd_fjo_search_repo(){
    param:scope     ___x_cmd_fjo
    param:dsl       '
options:
    #1              "The query contains one or more search keywords and qualifiers"         <>=""
    --limit         "Results per page"                                                      <>="30"
    --page          "Page number of the results to fetch."                                  <>="1"
    --topic         "Limit search to repositories with keyword as topic"                    <>:bool=""
    --sort          "sort"                                                                  <>="alpha"      = alpha created updated size id
    --order         "order"                                                                 <>="asc"  = desc asc
    --json|-j       "output origin json data"
'
    param:run
    local q="$1"
    if ___x_cmd_gx_output_is_format; then
         ___x_cmd_fjo_get_multi "/repos/search" topic sort order q | ___x_cmd_gx_output_format
    else
         ___x_cmd_fjo_get_multi "/repos/search" topic sort order q | \
            ___x_cmd jo .data                                                  | \
            ___x_cmd jo 2c            .full_name  .private .description        | \
            ___x_cmd csv header --add  RepoPath    Private  Description        | \
            if [ -n "$csv" ]; then  ___x_cmd_cmds cat
            else                    ___x_cmd csv app
            fi
    fi
}
