#!/usr/bin/env nu
# Thin entry for platform | plat | p commands.
# Loads ONLY platform modules (~50ms vs ~9s for the full entry).
# Bash wrapper routes this for all platform subcommands except logs (which needs interactive stdin).

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/commands/platform.nu *
use main_provisioning/flags.nu *

def main [
    ...args: string
    --check (-c)
    --debug (-x)
    --yes (-y)
    --notitles
    --services: string
]: nothing -> nothing {
    if $debug { $env.PROVISIONING_DEBUG = true }

    let cmd  = ($args | get 0? | default "")
    let ops  = ($args | skip 1 | str join " ")

    let flags = (parse_common_flags {
        check:    $check
        debug:    $debug
        yes:      $yes
        notitles: $notitles
        services: ($services | default "")
    })

    handle_platform_command $cmd $ops $flags
}
