use tools/nickel/process.nu [ncl-eval, default-ncl-paths] def disc-infra-name [ws_root: string]: nothing -> string { let infra_dir = ($ws_root | path join "infra") if not ($infra_dir | path exists) { error make {msg: $"No infra/ directory in workspace ($ws_root)"} } let candidates = ( ls $infra_dir | where type == dir | get name | each {|p| $p | path basename } | where {|n| ($ws_root | path join "infra" $n "settings.ncl") | path exists } ) if ($candidates | is-empty) { error make {msg: $"No infra//settings.ncl found under ($ws_root)/infra/"} } $candidates | first } # Resolve the Tier-2 (op-specific) or Tier-1 (CMD_TASK dispatch) script path # for a component operation. Returns {path: string, tier: int}. # # Tier 2: catalog/components///-.sh (preferred — per-op file) # Tier 1: catalog/components///install-.sh (CMD_TASK dispatch, pass op as $1) export def get-component-script-path [ name: string mode: string op: string ] { let prov = ($env.PROVISIONING? | default "") if ($prov | is-empty) { error make {msg: "PROVISIONING env var not set — cannot resolve component script path"} } let base = ($prov | path join "catalog" "components" $name $mode) let tier2 = ($base | path join $"($op)-($name).sh") if ($tier2 | path exists) { return {path: $tier2, tier: 2} } let tier1 = ($base | path join $"install-($name).sh") if ($tier1 | path exists) { return {path: $tier1, tier: 1} } error make {msg: $"No script for '($name)' mode=($mode) op=($op)\n Tier2 tried: ($tier2)\n Tier1 tried: ($tier1)"} } # Validate that an operation is enabled for a component in the workspace. # Reads ComponentDef.operations from the workspace NCL. Defaults to enabled=true # if the operations record does not contain the op key. export def validate-component-op [ ws_root: string component: string op: string ]: nothing -> nothing { let infra = (disc-infra-name $ws_root) let comp_ncl = ($ws_root | path join "infra" $infra "components" $"($component).ncl") if not ($comp_ncl | path exists) { error make {msg: $"Component '($component)' not in workspace ($ws_root)"} } let exported = (ncl-eval $comp_ncl (default-ncl-paths $ws_root)) let inner = ($exported | get -o $component | default null) if ($inner == null) { return } let ops = ($inner | get -o operations | default {}) let enabled = if ($op in $ops) { $ops | get $op } else { true } if not $enabled { error make {msg: $"Operation '($op)' is disabled for component '($component)' — set operations.($op) = true in workspace to enable"} } }