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

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

    local op="$1"
    case "$op" in
        --help|-h)  _____x_cmd_gcode_help --cfg              ;;
        init)       shift; ___x_cmd_gcode_cfg_init "$1"      ;;
        *)          ___x_cmd_gcode_cfg___invoke "$@"         ;;
    esac
}

# TODO: ___X_CMD_GCODE_CFG_VARLIST="token,owner,endpoint,repo,issue,mr"
___X_CMD_GCODE_CFG_VARLIST="token,owner,endpoint,repo"
___x_cmd_gcode_cfg___invoke(){
    # shellcheck disable=2154
    ___x_cmd_cfgy_obj   \
        --prefix            ___X_CMD_GCODE_CFG_DATA                  \
        --default-config    "${___X_CMD_ROOT_CFG}/gcode/X.cfg.yml"   \
        --current-config    "${___X_CMD_GCODE_LOCAL_CONFIG}"         \
        --current-profile   "${___X_CMD_GCODE_LOCAL_PROFILE}"        \
        --varlist           "$___X_CMD_GCODE_CFG_VARLIST"            \
        "$@"
}



___x_cmd_gcode_cur(){
    local X_help_cmd=; X_help_cmd='x help -m gcode --cur' help:arg:parse
    ___x_cmd_gcode_cfg --current "$@"
}


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

    ___x_cmd_gcode_cfg___invoke --init \
        token        "Set up Gitee token"                    "${cur_token}"        '=~*' "" -- \
        owner        "Set up owner name, not necessary"      "${cur_owner}"        '=~'  ""  "^[^:\\/ ]" -- \
        endpoint     "Set up endpoint"                       "${cur_endpoint}"     '='   "https://gitcode.net/api/v4" || return
}

