You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
55 lines
1.1 KiB
Plaintext
55 lines
1.1 KiB
Plaintext
def before_apply_all [ctx] {
|
|
let silo_ctx = (silo context | from json)
|
|
let config_file = ($silo_ctx.dirs.config | path join "silo.toml")
|
|
|
|
mut config = open-config $config_file
|
|
|
|
$config.template_context = ($config.template_context
|
|
| apply-defaults
|
|
| default {}
|
|
| merge (template-context $ctx $silo_ctx $config)
|
|
)
|
|
print $"Context updated to ($config.template_context)"
|
|
$config | save -f $config_file
|
|
}
|
|
|
|
def open-config [path: string] {
|
|
if ($path | path exists) {
|
|
open $path
|
|
} else {
|
|
{}
|
|
}
|
|
}
|
|
|
|
def template-context [ctx: any, silo_ctx: any, config: any] {
|
|
{
|
|
username: (whoami)
|
|
}
|
|
}
|
|
|
|
def apply-defaults [] {
|
|
let cfg = $in
|
|
{
|
|
system-id: ($cfg | get-or-prompt system-id)
|
|
environment: ($cfg | get-or-prompt environment)
|
|
font-size: ($cfg.font-size? | default 12)
|
|
icons: ($cfg.icons? | default false)
|
|
}
|
|
}
|
|
|
|
def get-or-prompt [key: string] {
|
|
$in | get -i $key | default-prompt $"Enter `($key)`: "
|
|
}
|
|
|
|
def default-prompt [prompt: string] {
|
|
default-with {|| input $prompt}
|
|
}
|
|
|
|
def default-with [fn] {
|
|
if $in == null {
|
|
do $fn
|
|
} else {
|
|
$in
|
|
}
|
|
}
|