# shellcheck shell=dash

___x_cmd_yq___main(){
    [ "$#" -gt 0 ] || {
        ___x_cmd_yq___cmd
        return
    }

    local op="$1";          shift
    case "$op" in
        -h|--help)  ___x_cmd help -m yq             "$@" ;;
        r|repl)         ___x_cmd_yq_repl            "$@" ;;
        --preparecmd)   ___x_cmd_yq___preparecmd    "$@" ;;

        --cmd)          ___x_cmd_yq___cmd           "$@" ;;
        *)              ___x_cmd_yq___cmd "$op"     "$@" ;;
    esac
}

___x_cmd_yq___cmd(){
    if ___x_cmd_hascmd yq; then
        case "$(command yq --version)" in
            *" v1."*|*" v2."*|*" v3."*|*" 1."*|*" 2."*|*" 3."*)
                ;;
            *)
                ___x_cmd_yq___cmd(){
                    command yq "$@"
                }
                ___x_cmd_yq___cmd "$@"
                return
        esac
    fi

    ___x_cmd_yq___cmd(){
        ___x_cmd snap --run --disable-command-check yq "$@"
    } && ___x_cmd_yq___cmd "$@"
}


___x_cmd_yq_repl(){
    ___X_CMD_JQ_REPL_CMD=yq ___x_cmd jq repl "$@"
}

___x_cmd_yq___preparecmd(){
    ___x_cmd snap --preparecmd yq
}
