139 lines
5.2 KiB
Text
139 lines
5.2 KiB
Text
#!/usr/bin/env nu
|
|
# prvng catalog — browse IaC building blocks in catalog/.
|
|
# Lists components, providers, taskservs, clusters, and domain artifacts.
|
|
|
|
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 { [] }))
|
|
}
|
|
|
|
def cat-root [] {
|
|
let prov = ($env.PROVISIONING? | default "")
|
|
if ($prov | is-empty) {
|
|
error make --unspanned { msg: "PROVISIONING env var not set" }
|
|
}
|
|
# Post-constellation-migration: env.nu may point to the constellation root
|
|
# while the catalog lives under code/. Try direct path first, then code/ sub-repo.
|
|
let direct = ($prov | path join "catalog")
|
|
if ($direct | path exists) { return $direct }
|
|
let via_code = ($prov | path join "code" "catalog")
|
|
if ($via_code | path exists) { return $via_code }
|
|
error make --unspanned { msg: $"catalog not found under ($prov) — check PROVISIONING" }
|
|
}
|
|
|
|
def list-catalog-dir [subdir: string]: nothing -> list {
|
|
let dir = (cat-root | path join $subdir)
|
|
if not ($dir | path exists) { return [] }
|
|
ls $dir
|
|
| where type == "dir"
|
|
| get name
|
|
| each { |p| $p | path basename }
|
|
}
|
|
|
|
def cmd-list [args: list<string>] {
|
|
let kind = $args | get 0? | default "all"
|
|
let all_kinds = ["components" "providers" "taskservs" "domains" "playbooks" "workflows"]
|
|
match $kind {
|
|
"components" | "comp" | "c" => {
|
|
let items = (list-catalog-dir "components")
|
|
if ($items | is-empty) { print "No components found" } else {
|
|
for n in $items { print $" ($n)" }
|
|
}
|
|
}
|
|
"providers" | "prov" => {
|
|
let items = (list-catalog-dir "providers")
|
|
if ($items | is-empty) { print "No providers found" } else {
|
|
for n in $items { print $" ($n)" }
|
|
}
|
|
}
|
|
"taskservs" | "ts" => {
|
|
let items = (list-catalog-dir "taskservs")
|
|
if ($items | is-empty) { print "No taskservs found" } else {
|
|
for n in $items { print $" ($n)" }
|
|
}
|
|
}
|
|
"domains" => {
|
|
let items = (list-catalog-dir "domains")
|
|
if ($items | is-empty) { print "No local domain artifacts" } else {
|
|
for n in $items { print $" ($n)" }
|
|
}
|
|
}
|
|
"playbooks" | "pb" => {
|
|
let items = (list-catalog-dir "playbooks")
|
|
if ($items | is-empty) { print "No playbooks found" } else {
|
|
for n in $items { print $" ($n)" }
|
|
}
|
|
}
|
|
"workflows" | "wf" => {
|
|
let items = (list-catalog-dir "workflows")
|
|
if ($items | is-empty) { print "No workflows found" } else {
|
|
for n in $items { print $" ($n)" }
|
|
}
|
|
}
|
|
"all" | _ => {
|
|
for k in $all_kinds {
|
|
let items = (list-catalog-dir $k)
|
|
if ($items | is-not-empty) {
|
|
print $"($k):"
|
|
$items | each { |n| print $" ($n)" }
|
|
print ""
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
def cmd-show [args: list<string>] {
|
|
let name = $args | get 0? | default ""
|
|
if ($name | is-empty) {
|
|
error make --unspanned { msg: "Usage: catalog show <name>" }
|
|
}
|
|
let root = (cat-root)
|
|
for kind in ["components" "providers" "taskservs" "domains" "playbooks" "workflows"] {
|
|
let dir = ($root | path join $kind $name)
|
|
if ($dir | path exists) {
|
|
print $"($kind)/($name)"
|
|
for f in (ls $dir | get name) { print $" ($f | path basename)" }
|
|
return
|
|
}
|
|
}
|
|
error make --unspanned { msg: $"'($name)' not found in catalog" }
|
|
}
|
|
|
|
def main [...args: string]: nothing -> nothing {
|
|
let cmd = $args | get 0? | default ""
|
|
let rest = if ($args | length) > 1 { $args | skip 1 } else { [] }
|
|
match $cmd {
|
|
"catalog" | "cat" => {
|
|
let sub = $rest | get 0? | default "list"
|
|
let sub_rest = if ($rest | length) > 1 { $rest | skip 1 } else { [] }
|
|
match $sub {
|
|
"list" | "ls" => { cmd-list $sub_rest }
|
|
"show" => { cmd-show $sub_rest }
|
|
_ => {
|
|
print "prvng catalog <subcommand>"
|
|
print ""
|
|
print "Subcommands:"
|
|
print " list [components|providers|taskservs|domains|playbooks|workflows] List catalog items"
|
|
print " show <name> Show item files"
|
|
}
|
|
}
|
|
}
|
|
_ => {
|
|
print "prvng catalog <subcommand>"
|
|
print ""
|
|
print "Subcommands:"
|
|
print " list [components|providers|taskservs|domains|playbooks|workflows]"
|
|
print " show <name>"
|
|
}
|
|
}
|
|
}
|