- Documented Fluent-based i18n system with locale detection - Bumped version from 1.0.10 to 1.0.11
168 lines
4.8 KiB
Plaintext
168 lines
4.8 KiB
Plaintext
#!/usr/bin/env nu
|
|
# Minimal Library - Fast path for interactive commands
|
|
# NO config loading, NO platform bootstrap
|
|
# Follows: @.claude/guidelines/nushell/NUSHELL_GUIDELINES.md
|
|
|
|
# Get user config path (centralized location)
|
|
# Rule 2: Single purpose function
|
|
# Cross-platform support (macOS, Linux, Windows)
|
|
def get-user-config-path [] {
|
|
let home = $env.HOME
|
|
let os_name = (uname | get operating-system | str downcase)
|
|
|
|
let config_path = match $os_name {
|
|
"darwin" => $"($home)/Library/Application Support/provisioning/user_config.yaml",
|
|
_ => $"($home)/.config/provisioning/user_config.yaml"
|
|
}
|
|
|
|
$config_path | path expand
|
|
}
|
|
|
|
# List all registered workspaces
|
|
# Rule 1: Explicit types, Rule 4: Early returns
|
|
# Rule 2: Single purpose - only list workspaces
|
|
export def workspace-list [] {
|
|
let user_config = (get-user-config-path)
|
|
|
|
# Rule 4: Early return if config doesn't exist
|
|
if not ($user_config | path exists) {
|
|
print "No workspaces configured yet."
|
|
return []
|
|
}
|
|
|
|
# Rule 15: Atomic read operation
|
|
# Rule 13: Try-catch for I/O operations
|
|
let config = (try {
|
|
open $user_config
|
|
} catch {|err|
|
|
print "Error reading user config: $err.msg"
|
|
return []
|
|
})
|
|
|
|
let active = ($config | get --optional active_workspace | default "")
|
|
let workspaces = ($config | get --optional workspaces | default [])
|
|
|
|
# Rule 8: Pure transformation (no side effects)
|
|
if ($workspaces | length) == 0 {
|
|
print "No workspaces registered."
|
|
return []
|
|
}
|
|
|
|
$workspaces | each {|ws|
|
|
{
|
|
name: $ws.name
|
|
path: $ws.path
|
|
active: ($ws.name == $active)
|
|
last_used: ($ws | get --optional last_used | default "Never")
|
|
}
|
|
}
|
|
}
|
|
|
|
# Get active workspace name
|
|
# Rule 1: Explicit types, Rule 4: Early returns
|
|
export def workspace-active [] {
|
|
let user_config = (get-user-config-path)
|
|
|
|
# Rule 4: Early return
|
|
if not ($user_config | path exists) {
|
|
return ""
|
|
}
|
|
|
|
# Rule 15: Atomic read, Rule 8: Pure function
|
|
try {
|
|
open $user_config | get --optional active_workspace | default ""
|
|
} catch {
|
|
""
|
|
}
|
|
}
|
|
|
|
# Get workspace info by name
|
|
# Rule 1: Explicit types, Rule 4: Early returns
|
|
export def workspace-info [name: string] {
|
|
let user_config = (get-user-config-path)
|
|
|
|
# Rule 4: Early return if config doesn't exist
|
|
if not ($user_config | path exists) {
|
|
return { name: $name, path: "", exists: false }
|
|
}
|
|
|
|
# Rule 15: Atomic read operation
|
|
let config = (try {
|
|
open $user_config
|
|
} catch {
|
|
return { name: $name, path: "", exists: false }
|
|
})
|
|
|
|
let workspaces = ($config | get --optional workspaces | default [])
|
|
let ws = ($workspaces | where { $in.name == $name } | first)
|
|
|
|
if ($ws | is-empty) {
|
|
return { name: $name, path: "", exists: false }
|
|
}
|
|
|
|
# Rule 8: Pure transformation
|
|
{
|
|
name: $ws.name
|
|
path: $ws.path
|
|
exists: true
|
|
last_used: ($ws | get --optional last_used | default "Never")
|
|
}
|
|
}
|
|
|
|
# Quick status check (orchestrator health + active workspace)
|
|
# Rule 1: Explicit types, Rule 13: Appropriate error handling
|
|
export def status-quick [] {
|
|
# Direct HTTP check (no bootstrap overhead)
|
|
# Rule 13: Use try-catch for network operations
|
|
let orch_health = (try {
|
|
http get --max-time 2sec "http://localhost:9090/health"
|
|
} catch {|err|
|
|
null
|
|
})
|
|
|
|
let orch_status = if ($orch_health != null) {
|
|
"running"
|
|
} else {
|
|
"stopped"
|
|
}
|
|
|
|
let active_ws = (workspace-active)
|
|
|
|
# Rule 8: Pure transformation
|
|
{
|
|
orchestrator: $orch_status
|
|
workspace: $active_ws
|
|
timestamp: (date now | format date "%Y-%m-%d %H:%M:%S")
|
|
}
|
|
}
|
|
|
|
# Display essential environment variables
|
|
# Rule 1: Explicit types, Rule 8: Pure function (read-only)
|
|
export def env-quick [] {
|
|
# Rule 8: No side effects, just reading env vars
|
|
{
|
|
PROVISIONING_ROOT: ($env.PROVISIONING_ROOT? | default "not set")
|
|
PROVISIONING_ENV: ($env.PROVISIONING_ENV? | default "not set")
|
|
PROVISIONING_DEBUG: ($env.PROVISIONING_DEBUG? | default "false")
|
|
HOME: $env.HOME
|
|
PWD: $env.PWD
|
|
}
|
|
}
|
|
|
|
# Show quick help for fast-path commands
|
|
# Rule 1: Explicit types, Rule 8: Pure function
|
|
export def quick-help [] {
|
|
"Provisioning CLI - Fast Path Commands
|
|
|
|
Quick Commands (< 100ms):
|
|
workspace list List all registered workspaces
|
|
workspace active Show currently active workspace
|
|
status Quick health check
|
|
env Show essential environment variables
|
|
help [command] Show help for a command
|
|
|
|
For full help:
|
|
provisioning help Show all available commands
|
|
provisioning help <command> Show help for specific command"
|
|
}
|