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

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

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

___x_cmd_gt_cur(){
    param:void
    local X_help_cmd=; X_help_cmd='x help -m gt --cur' help:arg:parse
    ___x_cmd_gt_cfg___invoke --current "$@"
}

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

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

# TODO: ___X_CMD_GT_CFG_VARLIST="token,owner,endpoint,repo,issue,pr"
___X_CMD_GT_CFG_VARLIST="token,owner,endpoint,repo"
___x_cmd_gt_cfg___invoke(){
     # shellcheck disable=2154
    ___x_cmd_cfgy_obj                                             \
        --prefix            ___X_CMD_GT_CFG_DATA                  \
        --default-config    "${___X_CMD_ROOT_CFG}/gt/X.cfg.yml"   \
        --current-config    "${___X_CMD_GT_LOCAL_CONFIG}"         \
        --current-profile   "${___X_CMD_GT_LOCAL_PROFILE}"        \
        --varlist           "$___X_CMD_GT_CFG_VARLIST"            \
        "$@"
}



