Jesús Pérez c62e967ce3
chore: complete KCL to Nickel migration cleanup and setup pre-commit
Clean up 404 KCL references (99.75% complete):
   - Rename kcl_* variables to schema_*/nickel_* (kcl_path→schema_path, etc.)
   - Update functions: parse_kcl_file→parse_nickel_file
   - Update env vars: KCL_MOD_PATH→NICKEL_IMPORT_PATH
   - Fix cli/providers-install: add has_nickel and nickel_version variables
   - Correct import syntax: .nickel.→.ncl.
   - Update 57 files across core, CLI, config, and utilities

   Configure pre-commit hooks:
   - Activate: nushell-check, nickel-typecheck, markdownlint
   - Comment out: Rust hooks (fmt, clippy, test), check-yaml

   Testing:
   - Module discovery: 9 modules (6 providers, 1 taskserv, 2 clusters) 
   - Syntax validation: 15 core files 
   - Pre-commit hooks: all passing 
2026-01-08 20:08:46 +00:00

95 lines
2.3 KiB
Plaintext

# Enhanced validation utilities for provisioning tool
export def validate-required [
value: any
name: string
context?: string
] {
if ($value | is-empty) {
print $"🛑 Required parameter '($name)' is missing or empty"
if ($context | is-not-empty) {
print $"Context: ($context)"
}
print $"💡 Please provide a value for '($name)'"
return false
}
true
}
export def validate-path [
path: string
context?: string
--must-exist
] {
if ($path | is-empty) {
print "🛑 Path parameter is empty"
if ($context | is-not-empty) {
print $"Context: ($context)"
}
return false
}
if $must_exist and not ($path | path exists) {
print $"🛑 Path '($path)' does not exist"
if ($context | is-not-empty) {
print $"Context: ($context)"
}
print "💡 Check if the path exists and you have proper permissions"
return false
}
true
}
export def validate-command [
command: string
context?: string
] {
let cmd_exists = (^bash -c $"type -P ($command)" | complete)
if $cmd_exists.exit_code != 0 {
print $"🛑 Command '($command)' not found in PATH"
if ($context | is-not-empty) {
print $"Context: ($context)"
}
print $"💡 Install '($command)' or add it to your PATH"
return false
}
true
}
export def safe-execute [
command: closure
context: string
--fallback: closure
] {
let result = (do $command | complete)
if $result.exit_code != 0 {
print $"⚠️ Warning: Error in ($context): ($result.stderr)"
if $fallback != null {
print "🔄 Executing fallback..."
do $fallback
} else {
print $"🛑 Execution failed in ($context)"
print $"Error: ($result.stderr)"
}
} else {
$result.stdout
}
}
export def validate-settings [
settings: record
required_fields: list
] {
let missing_fields = ($required_fields | where {|field|
($settings | try { get $field } catch { null } | is-empty)
})
if ($missing_fields | length) > 0 {
print "🛑 Missing required settings fields:"
$missing_fields | each {|field| print $" - ($field)"}
return false
}
true
}