prvng_core/nulib/provisioning-server-list.nu

76 lines
2.8 KiB
Text
Raw Normal View History

#!/usr/bin/env nu
# Thin entry for `server list` and `server sync`.
# Loads only servers/list.nu (~255ms vs ~1.15s for the full server handler).
# Bash wrapper routes `server list/ls/l/sync` here; all other server subcommands
# go to provisioning-server.nu.
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 { [] }))
let args_raw = ($env.PROVISIONING_ARGS? | default "")
$env.PROVISIONING_ARGS = ($args_raw | str replace --regex '^(server|s)\s+' '')
let _coerce = {|raw| $raw == "true" or $raw == "1" }
let raw_no_titles = ($env.PROVISIONING_NO_TITLES? | default "")
if ($raw_no_titles | describe) == "string" and ($raw_no_titles | is-not-empty) {
$env.PROVISIONING_NO_TITLES = (do $_coerce $raw_no_titles)
}
let raw_no_terminal = ($env.PROVISIONING_NO_TERMINAL? | default "")
if ($raw_no_terminal | describe) == "string" and ($raw_no_terminal | is-not-empty) {
$env.PROVISIONING_NO_TERMINAL = (do $_coerce $raw_no_terminal)
}
let raw_titles_shown = ($env.PROVISIONING_TITLES_SHOWN? | default "")
if ($raw_titles_shown | describe) == "string" and ($raw_titles_shown | is-not-empty) {
$env.PROVISIONING_TITLES_SHOWN = (do $_coerce $raw_titles_shown)
}
let raw_debug = ($env.PROVISIONING_DEBUG? | default "")
if ($raw_debug | describe) == "string" and ($raw_debug | is-not-empty) {
$env.PROVISIONING_DEBUG = (do $_coerce $raw_debug)
}
}
use servers/list.nu *
def main [
...args: string
--infra (-i): string = ""
--debug (-x)
--out: string = ""
]: nothing -> nothing {
if $debug { $env.PROVISIONING_DEBUG = true }
let first = ($args | get 0? | default "")
let rest = if $first in ["server" "s"] { $args | skip 1 } else { $args }
let subcmd = ($rest | get 0? | default "list")
match $subcmd {
"list" | "ls" | "lis" | "l" | "" => {
if ($infra | is-not-empty) {
main list --infra $infra --debug=$debug --out=$out
} else {
main list --debug=$debug --out=$out
}
}
"sync" => {
if ($infra | is-not-empty) {
main sync --infra $infra
} else {
main sync
}
}
_ => {
error make { msg: $"server-list handler received unexpected subcommand '($subcmd)'" }
}
}
}