79 lines
2.7 KiB
Plaintext
79 lines
2.7 KiB
Plaintext
|
|
# Generation Command Handlers
|
||
|
|
# Handles: generate commands (server, taskserv, cluster, infra)
|
||
|
|
|
||
|
|
use ../flags.nu *
|
||
|
|
use ../../lib_provisioning *
|
||
|
|
|
||
|
|
# 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 { "" }
|
||
|
|
|
||
|
|
# 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 " " | get -o 0)
|
||
|
|
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
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|