# shellcheck    shell=dash

xrc cfgy
___x_cmd_shodan_cfg(){
    [ "$#" -gt 0 ] || {
        ___x_cmd_shodan_init
        return
    }

    local op="$1"; shift
    case "$op" in
        -h|--help)      x help -m shodan --cfg ;;
        *)              ___x_cmd_shodan_cfg___invoke "$op" "$@" ;;
    esac
}

___x_cmd_shodan_cur(){
    local X_help_cmd=; X_help_cmd='x help -m shodan --cur' help:arg:parse
    ___x_cmd_shodan_cfg --current "$@"
}

___x_cmd_shodan_init(){
    local cur_key=; local cur_proxy=
    if [ -f "$(___x_cmd_shodan_cur --get config)" ]; then
        ___x_cmd_shodan_cur cur_key:=key cur_proxy:=proxy
    fi

    ___x_cmd_shodan_cfg___invoke --init    \
        key         "Set up the API key of shodan "      "${cur_key}"             \
                        '=~*'   "^[A-Za-z0-9_]+$"           --                    \
        proxy       "Set up the network proxy for API requests"                   \
                    "$cur_proxy" '=~'    "^([a-z0-9]+://)?[0-9.:]+$"
}

# Config setting the key.
# set the default prompt

___X_CMD_SHODAN_CFG_VARLIST="key,proxy"
___x_cmd_shodan_cfg___invoke(){
    ___x_cmd_cfgy_obj                                             \
        --prefix            ___X_CMD_SHODAN_CFG_DATA                \
        --default-config    "${___X_CMD_ROOT_CFG}/shodan/X.cfg.yml" \
        --current-config    "${___X_CMD_SHODAN_LOCAL_CONFIG}"       \
        --current-profile   "${___X_CMD_SHODAN_LOCAL_PROFILE}"      \
        --varlist           "$___X_CMD_SHODAN_CFG_VARLIST"          \
        "$@"
}


