fn run_correct_turbo(
    repo_state: RepoState,
    shim_args: ShimArgs,
    subscriber: &TurboSubscriber,
    ui: ColorConfig,
) -> Result<i32, Error> {
    let package_manager = repo_state.package_manager.as_ref();

    if let Some(turbo_state) = LocalTurboState::infer(&repo_state.root) {
        let mut builder = crate::config::TurborepoConfigBuilder::new(&repo_state.root);
        if let Some(root_turbo_json) = &shim_args.root_turbo_json {
            builder = builder.with_root_turbo_json_path(Some(root_turbo_json.clone()));
        }
        let config = builder.build().unwrap_or_default();

        try_check_for_updates(&shim_args, turbo_state.version(), &config, package_manager);

        if turbo_state.local_is_self() {
            env::set_var(
                cli::INVOCATION_DIR_ENV_VAR,
                shim_args.invocation_dir.as_path(),
            );
            debug!("Currently running turbo is local turbo.");
            Ok(cli::run(Some(repo_state), subscriber, ui)?)
        } else {
            spawn_local_turbo(&repo_state, turbo_state, shim_args)
        }
    } else if let Some(local_config) = LocalTurboConfig::infer(&repo_state) {
        debug!(
            "Found configuration for turbo version {}",
            local_config.turbo_version()
        );
        spawn_npx_turbo(&repo_state, local_config.turbo_version(), shim_args)
    } else {
        let version = get_version();
        let mut builder = crate::config::TurborepoConfigBuilder::new(&repo_state.root);
        if let Some(root_turbo_json) = &shim_args.root_turbo_json {
            builder = builder.with_root_turbo_json_path(Some(root_turbo_json.clone()));
        }
        let config = builder.build().unwrap_or_default();
        try_check_for_updates(&shim_args, version, &config, package_manager);
        // cli::run checks for this env var, rather than an arg, so that we can support
        // calling old versions without passing unknown flags.
        env::set_var(
            cli::INVOCATION_DIR_ENV_VAR,
            shim_args.invocation_dir.as_path(),
        );
        debug!("Running command as global turbo");
        let should_warn_on_global = env::var(TURBO_GLOBAL_WARNING_DISABLED)
            .map_or(true, |disable| !matches!(disable.as_str(), "1" | "true"));
        if should_warn_on_global {
            warn!("No locally installed `turbo` found. Using version: {version}.");
        }
        Ok(cli::run(Some(repo_state), subscriber, ui)?)
    }
}
Attempts to run correct turbo by finding nearest package.json,
then finding local turbo installation. If the current binary is the
local turbo installation, then we run current turbo. Otherwise we
kick over to the local turbo installation.

# Arguments

* `turbo_state`: state for current execution

returns: Result<i32, Error>
crates/turborepo-lib/src/shim/mod.rs