64 lines
2.6 KiB
Plaintext
Raw Normal View History

# Module: System Initialization
# Purpose: Handles system initialization, environment setup, and workspace initialization.
# Dependencies: error, interface, config/accessor
2025-10-07 10:32:04 +01:00
use ../config/accessor.nu *
export def show_titles [] {
2025-10-07 10:32:04 +01:00
if (detect_claude_code) { return false }
if ($env.PROVISIONING_NO_TITLES? | default false) { return }
if ($env.PROVISIONING_OUT | is-not-empty) { return }
# Prevent double title display
if ($env.PROVISIONING_TITLES_SHOWN? | default false) { return }
$env.PROVISIONING_TITLES_SHOWN = true
_print $"(_ansi blue_bold)(open -r ((get-provisioning-resources) | path join "ascii.txt"))(_ansi reset)"
}
export def use_titles [ ] {
2025-10-07 10:32:04 +01:00
if ($env.PROVISIONING_NO_TITLES? | default false) { return false }
if ($env.PROVISIONING_NO_TERMINAL? | default false) { return false }
let args = ($env.PROVISIONING_ARGS? | default "")
if ($args | is-not-empty) and ($args | str contains "-h" ) { return false }
if ($args | is-not-empty) and ($args | str contains "--notitles" ) { return false }
if ($args | is-not-empty) and ($args | str contains "query") and ($args | str contains "-o" ) { return false }
2025-10-07 10:32:04 +01:00
true
}
export def provisioning_init [
helpinfo: bool
module: string
args: list<string> # Other options, use help to get info
] {
2025-10-07 10:32:04 +01:00
if (use_titles) { show_titles }
if $helpinfo != null and $helpinfo {
let cmd_line: list<string> = if ($args| length) == 0 {
$args | str join " "
} else {
($env.PROVISIONING_ARGS? | default "")
}
let cmd_args: list<string> = ($cmd_line | str replace "--helpinfo" "" |
str replace "-h" "" | str replace $module "" | str trim | split row " "
)
if ($cmd_args | length) > 0 {
# Refactored from try-catch to do/complete for explicit error handling
let str_mod_0_result = (do { $cmd_args | get 0 } | complete)
let str_mod_0 = if $str_mod_0_result.exit_code == 0 { ($str_mod_0_result.stdout | str trim) } else { "" }
let str_mod_1_result = (do { $cmd_args | get 1 } | complete)
let str_mod_1 = if $str_mod_1_result.exit_code == 0 { ($str_mod_1_result.stdout | str trim) } else { "" }
if $str_mod_1 != "" {
let final_args = ($cmd_args | drop nth 0 1)
^$"((get-provisioning-name))" "-mod" $"'($str_mod_0) ($str_mod_1)'" ...$final_args help
} else if $str_mod_0 != "" {
let final_args = ($cmd_args | drop nth 0)
^$"((get-provisioning-name))" "-mod" ($str_mod_0) ...$final_args help
} else {
^$"((get-provisioning-name))" "-mod" $"($module | str replace ' ' '|')" ...$cmd_args help
}
2025-10-07 10:32:04 +01:00
} else {
^$"((get-provisioning-name))" help
}
exit 0
}
}