# shellcheck shell=sh
# shellcheck disable=SC3043,2034

xrc cfgy
___x_cmd_gl_cfg(){
    param:void
    [ "$#" -gt 0 ] || {
         _____x_cmd_gl_help --cfg
        return 64
    }

    local X_help_cmd=; X_help_cmd='x help -m gl --cfg' help:arg:parse
    ___x_cmd_gl_cfg___invoke "$@"
}

___x_cmd_gl_cur(){
    param:void
    local X_help_cmd=; X_help_cmd='x help -m gl --cur' help:arg:parse
    ___x_cmd_gl_cfg___invoke --current "$@"
}

___x_cmd_gl_init(){
    param:void
    local cur_token=; local cur_owner=; local cur_endpoint=
    if [ -f "$(___x_cmd_gl_cur --get config)" ]; then
        ___x_cmd_gl_cur cur_token:=token cur_owner:=owner cur_endpoint:=endpoint
    fi

    local X_help_cmd=; X_help_cmd='x help -m gl --init' help:arg:parse
    ___x_cmd_gl_cfg___invoke --init \
        token        "Set up GitLab token"                   "${cur_token}"        '=~*'  ""                -- \
        endpoint     "Set up endpoint"                       "${cur_endpoint:-"https://gitlab.com/api/v4"}" -- \
        owner        "Set up owner name (optional)"          "${cur_owner}"        '=~'   "^[^:\\/ ]"       || return
}

# TODO: ___X_CMD_GL_CFG_VARLIST="token,owner,endpoint,repo,issue,mr"
___X_CMD_GL_CFG_VARLIST="token,owner,endpoint,repo"
___x_cmd_gl_cfg___invoke(){
    # shellcheck disable=2154
    ___x_cmd_cfgy_obj   \
        --prefix            ___X_CMD_GL_CFG_DATA                  \
        --default-config    "${___X_CMD_ROOT_CFG}/gl/X.cfg.yml"   \
        --current-config    "${___X_CMD_GL_LOCAL_CONFIG}"         \
        --current-profile   "${___X_CMD_GL_LOCAL_PROFILE}"        \
        --varlist           "$___X_CMD_GL_CFG_VARLIST"            \
        "$@"
}
