Jesús Pérez 85ce530733
feat: update provisioning core CLI, libraries, and plugins
Update core components including CLI, Nushell libraries, plugins system,
and utility scripts for the provisioning system.

CLI Updates:
- Command implementations
- CLI utilities and dispatching
- Help system improvements
- Command validation

Library Updates:
- Configuration management system
- Infrastructure validation
- Extension system improvements
- Secrets management
- Workspace operations
- Cache management system

Plugin System:
- Interactive form plugin (inquire)
- KCL integration plugin
- Performance optimization plugins
- Plugin registration system

Utilities:
- Build and distribution scripts
- Installation procedures
- Testing utilities
- Development tools

Documentation:
- Library module documentation
- Extension API guides
- Plugin usage guides
- Service management documentation

All changes are backward compatible. No breaking changes.
2025-12-11 21:57:05 +00:00

148 lines
4.4 KiB
Plaintext

use utils *
use config/accessor.nu *
export def clip_copy [
msg: string
show: bool
]: nothing -> nothing {
if ( (version).installed_plugins | str contains "clipboard" ) {
$msg | clipboard copy
print $"(_ansi default_dimmed)copied into clipboard now (_ansi reset)"
} else {
if (not $show) { _print $msg }
}
}
export def notify_msg [
title: string
body: string
icon: string
time_body: string
timeout: duration
task?: closure
]: nothing -> nothing {
if ( (version).installed_plugins | str contains "desktop_notifications" ) {
if $task != null {
( notify -s $title -t $time_body --timeout $timeout -i $icon)
} else {
( notify -s $title -t $body --timeout $timeout -i $icon)
}
} else {
if $task != null {
_print (
$"(_ansi blue)($title)(_ansi reset)\n(_ansi blue_bold)($time_body)(_ansi reset)"
)
} else {
_print (
$"(_ansi blue)($title)(_ansi reset)\n(_ansi blue_bold)($body)(_ansi reset)"
)
}
}
}
export def show_qr [
url: string
]: nothing -> nothing {
# Try to use pre-generated QR code files
let qr_path = ((get-provisioning-resources) | path join "qrs" | path join ($url | path basename))
if ($qr_path | path exists) {
_print (open -r $qr_path)
} else {
# Fallback: display URL in reverse video format
_print $"(_ansi blue_reverse)($url)(_ansi reset)"
_print $"(_ansi purple)($url)(_ansi reset)"
}
}
export def port_scan [
ip: string
port: int
sec_timeout: int
]: nothing -> bool {
# Use netcat for port scanning - reliable and portable
(^nc -zv -w $sec_timeout ($ip | str trim) $port err> (if $nu.os-info.name == "windows" { "NUL" } else { "/dev/null" }) | complete).exit_code == 0
}
export def render_template [
template_path: string
vars: record
--ai_prompt: string
]: nothing -> string {
# Regular template rendering
if ( (version).installed_plugins | str contains "tera" ) {
$vars | tera-render $template_path
} else {
error make { msg: "nu_plugin_tera not available - template rendering not supported" }
}
}
export def render_template_ai [
ai_prompt: string
template_type: string = "template"
]: nothing -> string {
use ai/lib.nu *
ai_generate_template $ai_prompt $template_type
}
export def process_kcl_file [
kcl_file: string
format: string
settings?: record
]: nothing -> string {
# Try nu_plugin_kcl first if available
if ( (version).installed_plugins | str contains "kcl" ) {
if $settings != null {
let settings_json = ($settings | to json)
#kcl-run $kcl_file -Y $settings_json
let result = (^kcl run $kcl_file --setting $settings_json --format $format | complete)
if $result.exit_code == 0 { $result.stdout } else { error make { msg: $result.stderr } }
} else {
let result = (^kcl run $kcl_file --format $format | complete)
if $result.exit_code == 0 { $result.stdout } else { error make { msg: $result.stderr } }
}
} else {
# Use external KCL CLI
if (get-use-kcl) {
if $settings != null {
let settings_json = ($settings | to json)
let result = (^kcl run $kcl_file --setting $settings_json --format $format | complete)
if $result.exit_code == 0 { $result.stdout } else { error make { msg: $result.stderr } }
} else {
let result = (^kcl run $kcl_file --format $format | complete)
if $result.exit_code == 0 { $result.stdout } else { error make { msg: $result.stderr } }
}
} else {
error make { msg: "Neither nu_plugin_kcl nor external KCL CLI available" }
}
}
}
export def validate_kcl_schema [
kcl_file: string
data: record
]: nothing -> bool {
# Try nu_plugin_kcl first if available
if ( (version).installed_plugins | str contains "nu_plugin_kcl" ) {
kcl validate $kcl_file --data ($data | to json) catch {
# Fallback to external KCL CLI
if (get-use-kcl) {
let data_json = ($data | to json)
let data_json = ($data | to json)
let result = (^kcl validate $kcl_file --data ($data | to json) | complete)
$result.exit_code == 0
} else {
false
}
}
} else {
# Use external KCL CLI
if (get-use-kcl) {
let data_json = ($data | to json)
let result = (^kcl validate $kcl_file --data $data_json | complete)
$result.exit_code == 0
} else {
false
}
}
}