#!/usr/bin/env nu
# Thin entry for bootstrap command (~94ms vs ~9s through the full dispatcher).

export-env {
    let lib_dirs_raw = ($env.NU_LIB_DIRS? | default "")
    let current_lib_dirs = if ($lib_dirs_raw | type) == "string" {
        if ($lib_dirs_raw | is-empty) { [] } else { ($lib_dirs_raw | split row ":") }
    } else {
        $lib_dirs_raw
    }
    let dynamic = ($env.PROVISIONING? | default "" | path join "core" "nulib")
    $env.NU_LIB_DIRS = ([
        "/opt/provisioning/core/nulib"
        "/usr/local/provisioning/core/nulib"
    ] | append $current_lib_dirs | append (if ($dynamic | is-not-empty) { [$dynamic] } else { [] }))
}

use main_provisioning/bootstrap.nu *

def main [
    --workspace (-w): string
    --dry-run (-n)
    --debug (-x)
]: nothing -> nothing {
    if $debug { $env.PROVISIONING_DEBUG = true }
    let ws = ($workspace | default "")
    if $dry_run {
        if ($ws | is-not-empty) { main bootstrap --workspace $ws --dry-run } else { main bootstrap --dry-run }
    } else {
        if ($ws | is-not-empty) { main bootstrap --workspace $ws } else { main bootstrap }
    }
}
