prvng_core/nulib/main_provisioning/commands/generation.nu

147 lines
6 KiB
Text
Raw Normal View History

2025-10-07 10:32:04 +01:00
# Generation Command Handlers
# Handles: generate commands (server, taskserv, cluster, infra)
use ../flags.nu *
feat(core): three-layer DAG, unified component arch, commands-registry cache, Nushell 0.112.2 migration - DAG architecture: `dag show/validate/export` (nulib/main_provisioning/dag.nu), config loader (lib_provisioning/config/loader/dag.nu), taskserv dag-executor. Backed by schemas/lib/dag/*.ncl; orchestrator emits NATS events via WorkspaceComposition::into_workflow. See ADR-020, ADR-021. - Unified Component Architecture: components/mod.nu, main_provisioning/ {components,workflow,extensions,ontoref-queries}.nu. Full workflow engine with topological sort and NATS subject emission. Blocks A-H complete (libre-daoshi). - Commands-registry: nulib/commands-registry.ncl (Nickel source, 314 lines) + JSON cache at ~/.cache/provisioning/commands-registry.json rebuilt on source change. cli/provisioning fast-path alias expansion avoids cold Nu startup. ADDING_COMMANDS.md documents new-command workflow. - Platform service manager: service-manager.nu (+573), startup.nu (+611), service-check.nu (+255); autostart/bootstrap/health/target refactored. - Nushell 0.112.2 migration: removed all try/catch and bash redirections; external commands prefixed with ^; type signatures enforced. Driven by scripts/refactor-try-catch{,-simplified}.nu. - TTY stack: removed shlib/*-tty.sh; replaced by cli/tty-dispatch.sh, tty-filter.sh, tty-commands.conf. - New domain modules: images/ (golden image lifecycle), workspace/{state,sync}.nu, main_provisioning/{bootstrap,cluster-deploy,fip,state}.nu, commands/{state, build,integrations/auth,utilities/alias}.nu, platform.nu expanded (+874). - Config loader overhaul: loader/core.nu slimmed (-759), cache/core.nu refactored (-454), removed legacy loaders/file_loader.nu (-330). - Thirteen new provisioning-<domain>.nu top-level modules for bash dispatcher. - Tests: test_workspace_state.nu (+351); updates to test_oci_registry, test_services. - README + CHANGELOG updated.
2026-04-17 04:27:33 +01:00
# REMOVED: use ../../lib_provisioning * - causes circular import
2025-10-07 10:32:04 +01:00
# Helper to run module commands
def run_module [
args: string
module: string
option?: string
--exec
] {
let use_debug = if ($env.PROVISIONING_DEBUG? | default false) { "-x" } else { "" }
if $exec {
exec $"($env.PROVISIONING_NAME)" $use_debug -mod $module ($option | default "") $args
} else {
^$"($env.PROVISIONING_NAME)" $use_debug -mod $module ($option | default "") $args
}
}
# Main generation command dispatcher
export def handle_generation_command [
command: string
ops: string
flags: record
] {
let use_debug = if $flags.debug_mode { "-x" } else { "" }
let use_check = if $flags.check_mode { "--check " } else { "" }
let str_infra = if ($flags.infra | is-not-empty) { $"--infra ($flags.infra) " } else { "" }
let str_out = if ($flags.outfile | is-not-empty) { $"--outfile ($flags.outfile) " } else { "" }
let str_template = if ($flags.template | is-not-empty) { $"--template ($flags.template)" } else { "" }
let str_select = if ($flags.select | is-not-empty) { $"--select ($flags.select)" } else { "" }
# Handle Infrastructure-from-Code commands (detect, complete, workflow)
match $command {
"detect" => {
# Technology detection command - directly invoke module
let detect_module = ($env.PROVISIONING | path join "core" "nulib" "provisioning detect")
if ($detect_module | path exists) {
let path = if ($ops | is-not-empty) { ($ops | split row " " | first) } else { "." }
let out_fmt = if ($flags.output_format | is-not-empty) { $"--out ($flags.output_format)" } else { "" }
let pretty = if $flags.pretty_print { "--pretty" } else { "" }
exec nu $detect_module $path $out_fmt $pretty
} else {
print -e $"❌ Detection module not found at: ($detect_module)"
exit 1
}
return
}
"complete" => {
# Infrastructure completion command - directly invoke module
let complete_module = ($env.PROVISIONING | path join "core" "nulib" "provisioning complete")
if ($complete_module | path exists) {
let path = if ($ops | is-not-empty) { ($ops | split row " " | first) } else { "." }
let out_fmt = if ($flags.output_format | is-not-empty) { $"--out ($flags.output_format)" } else { "" }
let check = if $flags.check_mode { "--check" } else { "" }
let pretty = if $flags.pretty_print { "--pretty" } else { "" }
exec nu $complete_module $path $out_fmt $check $pretty
} else {
print -e $"❌ Completion module not found at: ($complete_module)"
exit 1
}
return
}
"workflow" => {
# Full Infrastructure-from-Code workflow - directly invoke module
let workflow_module = ($env.PROVISIONING | path join "core" "nulib" "provisioning workflow")
if ($workflow_module | path exists) {
let path = if ($ops | is-not-empty) { ($ops | split row " " | first) } else { "." }
let org = if ($flags.org | is-not-empty) { $"--org ($flags.org)" } else { "" }
let out_fmt = if ($flags.output_format | is-not-empty) { $"--out ($flags.output_format)" } else { "" }
let apply = if $flags.apply_changes { "--apply" } else { "" }
let verbose = if $flags.verbose_output { "--verbose" } else { "" }
let pretty = if $flags.pretty_print { "--pretty" } else { "" }
exec nu $workflow_module $path $org $out_fmt $apply $verbose $pretty
} else {
print -e $"❌ Workflow module not found at: ($workflow_module)"
exit 1
}
return
}
"orchestrate" => {
# IaC → Orchestrator integration - directly invoke module
let orch_module = ($env.PROVISIONING | path join "core" "nulib" "provisioning orchestrate")
if ($orch_module | path exists) {
let path = if ($ops | is-not-empty) { ($ops | split row " " | first) } else { "." }
let org = if ($flags.org | is-not-empty) { $"--org ($flags.org)" } else { "" }
let infra = if ($flags.infra | is-not-empty) { $"--infra ($flags.infra)" } else { "" }
let verbose = if $flags.verbose_output { "--verbose" } else { "" }
let dry_run = if $flags.dry_run { "--dry-run" } else { "" }
exec nu $orch_module $path $org $infra $verbose $dry_run
} else {
print -e $"❌ Orchestration module not found at: ($orch_module)"
exit 1
}
return
}
_ => { } # Fall through to regular generate command handling
}
2025-10-07 10:32:04 +01:00
# If no subcommand, show general generate help
if ($ops | is-empty) {
exec $"($env.PROVISIONING_NAME)" $use_debug "generate" $ops $use_check $str_infra $str_out
return
}
let target = ($ops | split row " " | first | default null)
2025-10-07 10:32:04 +01:00
let gen_ops = ($ops | split row " " | skip 1 | str join " ") + $" ($str_infra) ($str_template) ($str_out) ($use_check) ($use_debug) ($str_select)"
match $target {
"s" | "server" => {
run_module $"- ($gen_ops)" "server" "generate" --exec
}
"t" | "task" | "taskserv" => {
run_module $"- ($gen_ops)" "taskserv" "generate" --exec
}
"i" | "infra" | "infras" => {
run_module $"- ($gen_ops)" "infra" "generate" --exec
}
"cl" | "cluster" => {
run_module $"- ($gen_ops)" "cluster" "generate" --exec
}
"h" | "help" => {
_print $"\n(provisioning_generate_options)"
exit
}
"new" => {
exec $"($env.PROVISIONING_NAME)" $use_debug "generate" "new" $gen_ops $str_template $use_check $str_infra $str_out
}
_ => {
print $"❌ Unknown generate target: ($target)"
print ""
print "Available generate targets:"
print " server - Generate server configurations"
print " taskserv - Generate taskserv definitions"
print " cluster - Generate cluster configurations"
print " infra - Generate infrastructure setup"
print " new - Generate new infrastructure from scratch"
print ""
print "Use 'provisioning generate help' for more details"
exit 1
}
}
}