# shellcheck shell=dash

___x_cmd log init npx

___x_cmd_npx___main(){
    [ "$#" -gt 0 ] || {
        ___x_cmd_npx___help
        return
    }

    local op="$1";      shift
    case "$op" in
        *)              ___x_cmd_npx___cmd npx "$op"    "$@" ;;
    esac
}

___x_cmd_npx___cmd(){
    ___x_cmd_hasbin "$1" || {
        if ___x_cmd_is_stdout2tty && ___x_cmd_runmode_allow_manual; then
            npx:info "Node not found."
            local cmd=
            ___x_cmd ui select ,cmd  "What's next:"    \
                "x env use node"                \
                "x env try node"                \
                "x install node"                \
                "return 1"                      || return 1
            eval "$cmd"
        else
            npx:error --tip1 'x env use node' --tip2 'x env try node' "Node not found."
            return 1
        fi
    }

    "$@"
}


# shellcheck disable=SC2120
___x_cmd_npx___help(){
    ___x_cmd help -m npx "$@" 1>&2
    return 1
}
