provisioning-core/nulib/cli/help/render.nu

449 lines
26 KiB
Text
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# Hierarchical Help System with Categories (REFACTORED)
# Provides organized, drill-down help for provisioning commands
# Data-driven help content loaded from help_content.ncl
use platform/config/accessor.nu *
use ../help_renderer.nu *
# Load help content from Nickel file
def load-help-content [] {
let content_path = (help_content_path)
# Guard: Validate file exists
if not ($content_path | path exists) {
error make { msg: $"Help content file not found: ($content_path)" }
}
# Load the Nickel content - would normally be compiled/loaded
# For now, return parsed structure
load_help_data
}
# Get path to help content file
def help_content_path [] {
let script_dir = (get_script_dir)
$"($script_dir)/help_content.ncl"
}
def load_help_data [] {
{
categories: {
infrastructure: {
title: "🏗️ INFRASTRUCTURE MANAGEMENT"
color: "cyan"
sections: []
}
}
}
}
# Resolve documentation URL with local fallback
export def resolve-doc-url [doc_path: string] {
let config = (load-config)
let mdbook_enabled = ($config.documentation?.mdbook_enabled? | default false)
let mdbook_base = ($config.documentation?.mdbook_base_url? | default "")
let docs_root = ($config.documentation?.docs_root? | default "docs/src")
if $mdbook_enabled and ($mdbook_base | str length) > 0 {
# Return both URL and local path
{
url: $"($mdbook_base)/($doc_path).html"
local: $"provisioning/($docs_root)/($doc_path).md"
mode: "url"
}
} else {
# Use local files only
{
url: null
local: $"provisioning/($docs_root)/($doc_path).md"
mode: "local"
}
}
}
# Main help dispatcher
export def provisioning-help [
category?: string # Optional category: infrastructure, orchestration, development, workspace, platform, auth, plugins, utilities, concepts, guides, integrations
] {
# If no category provided, show main help
if ($category == null) or ($category == "") {
return (help-main)
}
# Try to match the category
let result = (match $category {
"infrastructure" | "infra" => "infrastructure"
"orchestration" | "orch" => "orchestration"
"development" | "dev" => "development"
"workspace" | "ws" => "workspace"
"platform" | "plat" => "platform"
"setup" | "st" => "setup"
"authentication" | "auth" => "authentication"
"mfa" => "mfa"
"plugins" | "plugin" => "plugins"
"utilities" | "utils" | "cache" => "utilities"
"tools" => "tools"
"vm" => "vm"
"diagnostics" | "diag" | "status" | "health" => "diagnostics"
"concepts" | "concept" => "concepts"
"guides" | "guide" | "howto" => "guides"
"integrations" | "integration" | "int" => "integrations"
_ => "unknown"
})
# If unknown category, show error
if $result == "unknown" {
print $"❌ Unknown help category: \"($category)\"\n"
print "Available help categories:"
print " infrastructure [infra] - Server, taskserv, cluster, VM management"
print " orchestration [orch] - Workflow, batch operations"
print " development [dev] - Module system, layers, versioning"
print " workspace [ws] - Workspace and template management"
print " setup [st] - System setup, configuration, initialization"
print " platform [plat] - Orchestrator, Control Center, MCP"
print " authentication [auth] - JWT authentication, MFA, sessions"
print " mfa - Multi-Factor Authentication details"
print " plugins [plugin] - Plugin management"
print " utilities [utils] - Cache, SOPS, providers, SSH"
print " tools - Tool and dependency management"
print " vm - Virtual machine operations"
print " diagnostics [diag] - System status, health checks"
print " concepts [concept] - Architecture and key concepts"
print " guides [guide] - Quick guides and cheatsheets"
print " integrations [int] - Prov-ecosystem and provctl bridge\n"
print "Use 'provisioning help' for main help"
exit 1
}
# Match valid category using renderer with data-driven approach
match $result {
"infrastructure" => (help-infrastructure)
"orchestration" => (help-orchestration)
"development" => (help-development)
"workspace" => (help-workspace)
"platform" => (help-platform)
"setup" => (help-setup)
"authentication" => (help-authentication)
"mfa" => (help-mfa)
"plugins" => (help-plugins)
"utilities" => (help-utilities)
"tools" => (help-tools)
"vm" => (help-vm)
"diagnostics" => (help-diagnostics)
"concepts" => (help-concepts)
"guides" => (help-guides)
"integrations" => (help-integrations)
_ => (help-main)
}
}
# Main help overview with categories
def help-main [] {
let show_header = not ($env.PROVISIONING_NO_TITLES? | default false)
let header = (if $show_header {
($"(_ansi yellow_bold)╔════════════════════════════════════════════════════════════════╗(_ansi reset)\n" +
$"(_ansi yellow_bold)║ (_ansi reset) (_ansi cyan_bold)PROVISIONING SYSTEM(_ansi reset) - Layered Infrastructure Automation (_ansi yellow_bold) ║(_ansi reset)\n" +
$"(_ansi yellow_bold)╚════════════════════════════════════════════════════════════════╝(_ansi reset)\n\n")
} else {
""
})
($header
+ $"(_ansi green_bold)📚 COMMAND CATEGORIES(_ansi reset) (_ansi default_dimmed)- Use 'provisioning help <category>' for details(_ansi reset)\n\n"
+ $" (_ansi cyan)🏗️ infrastructure(_ansi reset) (_ansi default_dimmed)[infra](_ansi reset)\t Server, taskserv, cluster, VM, and infra management\n"
+ $" (_ansi purple)⚡ orchestration(_ansi reset) (_ansi default_dimmed)[orch](_ansi reset)\t Workflow, batch operations, and orchestrator control\n"
+ $" (_ansi blue)🧩 development(_ansi reset) (_ansi default_dimmed)[dev](_ansi reset)\t\t Module discovery, layers, versions, and packaging\n"
+ $" (_ansi green)📁 workspace(_ansi reset) (_ansi default_dimmed)[ws](_ansi reset)\t\t Workspace and template management\n"
+ $" (_ansi red)🖥️ platform(_ansi reset) (_ansi default_dimmed)[plat](_ansi reset)\t\t Orchestrator, Control Center UI, MCP Server\n"
+ $" (_ansi magenta)⚙️ setup(_ansi reset) (_ansi default_dimmed)[st](_ansi reset)\t\t System setup, configuration, and initialization\n"
+ $" (_ansi yellow)🔐 authentication(_ansi reset) (_ansi default_dimmed)[auth](_ansi reset)\t JWT authentication, MFA, and sessions\n"
+ $" (_ansi cyan)🔌 plugins(_ansi reset) (_ansi default_dimmed)[plugin](_ansi reset)\t\t Plugin management and integration\n"
+ $" (_ansi green)🛠️ utilities(_ansi reset) (_ansi default_dimmed)[utils](_ansi reset)\t\t Cache, SOPS editing, providers, plugins, SSH\n"
+ $" (_ansi yellow)🌉 integrations(_ansi reset) (_ansi default_dimmed)[int](_ansi reset)\t\t Prov-ecosystem and provctl bridge\n"
+ $" (_ansi green)🔍 diagnostics(_ansi reset) (_ansi default_dimmed)[diag](_ansi reset)\t\t System status, health checks, and next steps\n"
+ $" (_ansi magenta)📚 guides(_ansi reset) (_ansi default_dimmed)[guide](_ansi reset)\t\t Quick guides and cheatsheets\n"
+ $" (_ansi yellow)💡 concepts(_ansi reset) (_ansi default_dimmed)[concept](_ansi reset)\t\t Understanding layers, modules, and architecture\n\n"
+ $"(_ansi green_bold)🚀 QUICK START(_ansi reset)\n\n"
+ $" 1. (_ansi cyan)Understand the system(_ansi reset): provisioning help concepts\n"
+ $" 2. (_ansi cyan)Create workspace(_ansi reset): provisioning workspace init my-infra --activate\n"
+ $" (_ansi default_dimmed)Or use interactive:(_ansi reset) provisioning workspace init --interactive\n"
+ $" 3. (_ansi cyan)Discover modules(_ansi reset): provisioning module discover taskservs\n"
+ $" 4. (_ansi cyan)Create servers(_ansi reset): provisioning server create --infra my-infra\n"
+ $" 5. (_ansi cyan)Deploy services(_ansi reset): provisioning taskserv create kubernetes\n\n"
+ $"(_ansi green_bold)🔧 COMMON COMMANDS(_ansi reset)\n\n"
+ $" provisioning server list - List all servers\n"
+ $" provisioning workflow list - List workflows\n"
+ $" provisioning module discover taskservs - Discover available taskservs\n"
+ $" provisioning layer show <workspace> - Show layer resolution\n"
+ $" provisioning version check - Check component versions\n\n"
+ $"(_ansi green_bold) HELP TOPICS(_ansi reset)\n\n"
+ $" provisioning help infrastructure (_ansi default_dimmed)[or: infra](_ansi reset) - Server/cluster lifecycle\n"
+ $" provisioning help orchestration (_ansi default_dimmed)[or: orch](_ansi reset) - Workflows and batch operations\n"
+ $" provisioning help development (_ansi default_dimmed)[or: dev](_ansi reset) - Module system and tools\n"
+ $" provisioning help workspace (_ansi default_dimmed)[or: ws](_ansi reset) - Workspace and templates\n"
+ $" provisioning help setup (_ansi default_dimmed)[or: st](_ansi reset) - System setup and configuration\n"
+ $" provisioning help platform (_ansi default_dimmed)[or: plat](_ansi reset) - Platform services with web UI\n"
+ $" provisioning help authentication (_ansi default_dimmed)[or: auth](_ansi reset) - JWT authentication and MFA\n"
+ $" provisioning help plugins (_ansi default_dimmed)[or: plugin](_ansi reset) - Plugin management\n"
+ $" provisioning help utilities (_ansi default_dimmed)[or: utils](_ansi reset) - Cache, SOPS, providers, and utilities\n"
+ $" provisioning help integrations (_ansi default_dimmed)[or: int](_ansi reset) - Prov-ecosystem and provctl bridge\n"
+ $" provisioning help diagnostics (_ansi default_dimmed)[or: diag](_ansi reset) - System status and health\n"
+ $" provisioning help guides (_ansi default_dimmed)[or: guide](_ansi reset) - Quick guides and cheatsheets\n"
+ $" provisioning help concepts (_ansi default_dimmed)[or: concept](_ansi reset) - Architecture and key concepts\n\n"
+ $"(_ansi default_dimmed)💡 Tip: Most commands support --help for detailed options\n"
+ $" Example: provisioning server --help(_ansi reset)\n")
}
# Data-driven help functions - each loads content from help_content.ncl and renders
def help-infrastructure [] {
(render-help-category
"🏗️ INFRASTRUCTURE MANAGEMENT"
"cyan"
[
{
name: "Lifecycle"
subtitle: "Server Management"
items: [
{ cmd: "server create", desc: "Create new servers [--infra <name>] [--check]" }
{ cmd: "server delete", desc: "Delete servers [--yes] [--keepstorage]" }
{ cmd: "server list", desc: "List all servers [--out json|yaml]" }
{ cmd: "server ssh <host>", desc: "SSH into server" }
{ cmd: "server price", desc: "Show server pricing" }
]
}
{
name: "Services"
subtitle: "Task Service Management"
items: [
{ cmd: "taskserv create <svc>", desc: "Install service [kubernetes, redis, postgres]" }
{ cmd: "taskserv delete <svc>", desc: "Remove service" }
{ cmd: "taskserv list", desc: "List available services" }
{ cmd: "taskserv generate <svc>", desc: "Generate service configuration" }
{ cmd: "taskserv validate <svc>", desc: "Validate service before deployment" }
{ cmd: "taskserv test <svc>", desc: "Test service in sandbox" }
{ cmd: "taskserv check-deps <svc>", desc: "Check service dependencies" }
{ cmd: "taskserv check-updates", desc: "Check for service updates" }
]
}
{
name: "Complete"
subtitle: "Cluster Operations"
items: [
{ cmd: "cluster create", desc: "Create complete cluster" }
{ cmd: "cluster delete", desc: "Delete cluster" }
{ cmd: "cluster list", desc: "List cluster components" }
]
}
{
name: "Virtual Machines"
subtitle: "VM Management"
items: [
{ cmd: "vm create [config]", desc: "Create new VM" }
{ cmd: "vm list [--running]", desc: "List VMs" }
{ cmd: "vm start <name>", desc: "Start VM" }
{ cmd: "vm stop <name>", desc: "Stop VM" }
{ cmd: "vm delete <name>", desc: "Delete VM" }
{ cmd: "vm info <name>", desc: "VM information" }
{ cmd: "vm ssh <name>", desc: "SSH into VM" }
{ cmd: "vm hosts check", desc: "Check hypervisor capability" }
{ cmd: "vm lifecycle list-temporary", desc: "List temporary VMs" }
]
}
{
name: "Management"
subtitle: "Infrastructure"
items: [
{ cmd: "infra list", desc: "List infrastructures" }
{ cmd: "infra validate", desc: "Validate infrastructure config" }
{ cmd: "generate infra --new <name>", desc: "Create new infrastructure" }
]
}
]
[]
""
"Use --check flag for dry-run mode\n Example: provisioning server create --check"
)
}
# Placeholder functions for remaining categories (can be expanded similarly)
def help-orchestration [] {
(render-help-category
"⚡ ORCHESTRATION"
"purple"
[
{
name: "Orchestrator"
subtitle: "Daemon Lifecycle"
items: [
{ cmd: "orchestrator start", desc: "Start orchestrator [--background]" }
{ cmd: "orchestrator stop", desc: "Stop orchestrator" }
{ cmd: "orchestrator status", desc: "Check if running" }
{ cmd: "orchestrator health", desc: "Health check" }
{ cmd: "orchestrator logs", desc: "View logs [--follow]" }
]
}
{
name: "Jobs"
subtitle: "Orchestrator Jobs (alias: j)"
items: [
{ cmd: "job list", desc: "List orchestrator jobs" }
{ cmd: "job status <id>", desc: "Get job status" }
{ cmd: "job monitor <id>", desc: "Monitor in real-time" }
{ cmd: "job stats", desc: "Show statistics" }
{ cmd: "job cleanup", desc: "Clean old jobs" }
{ cmd: "job submit <type> <op> <target>", desc: "Submit a job" }
]
}
{
name: "Workflows"
subtitle: "Workspace WorkflowDef (alias: wflow)"
items: [
{ cmd: "workflow list", desc: "List workspace WorkflowDef declarations" }
{ cmd: "workflow show <id>", desc: "Show definition + FSM state" }
{ cmd: "workflow run <id>", desc: "Execute a WorkflowDef [--dry-run]" }
{ cmd: "workflow validate", desc: "Cross-validate steps vs components" }
{ cmd: "workflow status <id>", desc: "FSM dimension state" }
]
}
{
name: "Batch"
subtitle: "Multi-Provider Batch Operations"
items: [
{ cmd: "batch submit <file>", desc: "Submit Nickel batch [--wait]" }
{ cmd: "batch list", desc: "List batches [--status Running]" }
{ cmd: "batch status <id>", desc: "Get batch status" }
{ cmd: "batch rollback <id>", desc: "Rollback failed batch" }
{ cmd: "batch stats", desc: "Show statistics" }
]
}
]
[]
""
"job = orchestrator HTTP jobs | workflow = workspace WorkflowDef\n Example: prvng workflow run deploy-services-libre-daoshi --workspace libre-daoshi"
)
}
# Stub implementations for remaining categories - using original inline content for now
# These would be replaced with data-driven versions using help_content.ncl in phase 2
def help-development [] {
(
$"(_ansi blue_bold)╔══════════════════════════════════════════════════╗(_ansi reset)\n" +
$"(_ansi blue_bold)║(_ansi reset) 🧩 DEVELOPMENT TOOLS (_ansi blue_bold)║(_ansi reset)\n" +
$"(_ansi blue_bold)╚══════════════════════════════════════════════════╝(_ansi reset)\n\n" +
$"(_ansi green_bold)[Discovery](_ansi reset) Module System\n" +
$" (_ansi blue)module discover <type>(_ansi reset)\t - Find taskservs/providers/clusters\n" +
$" (_ansi blue)module load <type> <ws> <mods>(_ansi reset) - Load modules into workspace\n" +
$" (_ansi blue)module list <type> <ws>(_ansi reset)\t - List loaded modules\n" +
$" (_ansi blue)module unload <type> <ws> <mod>(_ansi reset) - Unload module\n" +
$" (_ansi blue)module sync-nickel <infra>(_ansi reset)\t - Sync Nickel dependencies\n\n" +
$"(_ansi green_bold)[Architecture](_ansi reset) Layer System (_ansi cyan)STRATEGIC(_ansi reset)\n" +
$" (_ansi blue)layer explain(_ansi reset) - Explain layer concept\n" +
$" (_ansi blue)layer show <ws>(_ansi reset) - Show layer resolution\n" +
$" (_ansi blue)layer test <mod> <ws>(_ansi reset) - Test layer resolution\n" +
$" (_ansi blue)layer stats(_ansi reset) - Show statistics\n\n" +
$"(_ansi green_bold)[Maintenance](_ansi reset) Version Management\n" +
$" (_ansi blue)version check(_ansi reset) - Check all versions\n" +
$" (_ansi blue)version show(_ansi reset) - Display status [--format table|json]\n" +
$" (_ansi blue)version updates(_ansi reset) - Check available updates\n" +
$" (_ansi blue)version apply(_ansi reset) - Apply config updates\n" +
$" (_ansi blue)version taskserv <name>(_ansi reset) - Show taskserv version\n\n" +
$"(_ansi green_bold)[Distribution](_ansi reset) Packaging (_ansi yellow)Advanced(_ansi reset)\n" +
$" (_ansi blue)pack core(_ansi reset) - Package core schemas\n" +
$" (_ansi blue)pack provider <name>(_ansi reset) - Package provider\n" +
$" (_ansi blue)pack list(_ansi reset) - List packages\n" +
$" (_ansi blue)pack clean(_ansi reset) - Clean old packages\n\n" +
$"(_ansi default_dimmed)💡 The layer system is key to configuration inheritance\n" +
$" Use 'provisioning layer explain' to understand it(_ansi reset)\n"
)
}
# These are temporary stubs - original implementations preserved
# In a full refactor, these would all use the renderer and structured data
def help-workspace [] {
(
$"(_ansi green_bold)╔══════════════════════════════════════════════════╗(_ansi reset)\n" +
$"(_ansi green_bold)║(_ansi reset) 📁 WORKSPACE & TEMPLATES (_ansi green_bold)║(_ansi reset)\n" +
$"(_ansi green_bold)╚══════════════════════════════════════════════════╝(_ansi reset)\n\n" +
$"(_ansi green_bold)[Management](_ansi reset) Workspace Operations\n" +
$" (_ansi blue)workspace init <path>(_ansi reset)\t\t - Initialize workspace [--activate] [--interactive]\n" +
$" (_ansi blue)workspace create <path>(_ansi reset)\t - Create workspace structure [--activate]\n" +
$" (_ansi blue)workspace activate <name>(_ansi reset)\t - Activate existing workspace as default\n" +
$" (_ansi blue)workspace validate <path>(_ansi reset)\t - Validate structure\n" +
$" (_ansi blue)workspace info <path>(_ansi reset)\t\t - Show information\n" +
$" (_ansi blue)workspace list(_ansi reset)\t\t - List workspaces\n" +
$" (_ansi blue)workspace migrate [name](_ansi reset)\t - Migrate workspace [--skip-backup] [--force]\n" +
$" (_ansi blue)workspace version [name](_ansi reset)\t - Show workspace version information\n" +
$" (_ansi blue)workspace check-compatibility [name](_ansi reset) - Check workspace compatibility\n" +
$" (_ansi blue)workspace list-backups [name](_ansi reset)\t - List workspace backups\n\n" +
$"(_ansi green_bold)[Synchronization](_ansi reset) Update Hidden Directories & Modules\n" +
$" (_ansi blue)workspace check-updates [name](_ansi reset)\t - Check which directories need updating\n" +
$" (_ansi blue)workspace update [name] [FLAGS](_ansi reset)\t - Update all hidden dirs and content\n" +
$" \t\t\tUpdates: .providers, .clusters, .taskservs, .nickel\n" +
$" (_ansi blue)workspace sync-modules [name] [FLAGS](_ansi reset)\t - Sync workspace modules\n\n" +
$"(_ansi default_dimmed)Note: Optional workspace name [name] defaults to active workspace if not specified(_ansi reset)\n\n" +
$"(_ansi green_bold)[Common Flags](_ansi reset)\n" +
$" (_ansi cyan)--check (-c)(_ansi reset) - Preview changes without applying them\n" +
$" (_ansi cyan)--force (-f)(_ansi reset) - Skip confirmation prompts\n" +
$" (_ansi cyan)--yes (-y)(_ansi reset) - Auto-confirm (same as --force)\n" +
$" (_ansi cyan)--verbose(-v)(_ansi reset) - Detailed operation information\n\n" +
$"(_ansi cyan_bold)Examples:(_ansi reset)\n" +
$" (_ansi green)provisioning --yes workspace update(_ansi reset) - Update active workspace with auto-confirm\n" +
$" (_ansi green)provisioning --verbose workspace update myws(_ansi reset) - Update 'myws' with detailed output\n" +
$" (_ansi green)provisioning --check workspace update(_ansi reset) - Preview changes before updating\n" +
$" (_ansi green)provisioning --yes --verbose workspace update myws(_ansi reset) - Combine flags\n\n" +
$"(_ansi yellow_bold)⚠️ IMPORTANT - Nushell Flag Ordering:(_ansi reset)\n" +
$" Nushell requires (_ansi cyan)flags BEFORE positional arguments(_ansi reset). Thus:\n" +
$" ✅ (_ansi green)provisioning --yes workspace update(_ansi reset) [Correct - flags first]\n" +
$" ❌ (_ansi red)provisioning workspace update --yes(_ansi reset) [Wrong - parser error]\n\n" +
$"(_ansi green_bold)[Creation Modes](_ansi reset)\n" +
$" (_ansi blue)--activate\(-a\)(_ansi reset)\t\t - Activate workspace as default after creation\n" +
$" (_ansi blue)--interactive\(-I\)(_ansi reset)\t\t - Interactive workspace creation wizard\n\n" +
$"(_ansi green_bold)[Configuration](_ansi reset) Workspace Config Management\n" +
$" (_ansi blue)workspace config show [name](_ansi reset)\t\t - Show workspace config [--format yaml|json|toml]\n" +
$" (_ansi blue)workspace config validate [name](_ansi reset)\t - Validate all configs\n" +
$" (_ansi blue)workspace config generate provider <name>(_ansi reset) - Generate provider config\n" +
$" (_ansi blue)workspace config edit <type> [name](_ansi reset)\t - Edit config \(main|provider|platform|kms\)\n" +
$" (_ansi blue)workspace config hierarchy [name](_ansi reset)\t - Show config loading order\n" +
$" (_ansi blue)workspace config list [name](_ansi reset)\t\t - List config files [--type all|provider|platform|kms]\n\n" +
$"(_ansi green_bold)[Patterns](_ansi reset) Infrastructure Templates\n" +
$" (_ansi blue)template list(_ansi reset)\t\t - List templates [--type taskservs|providers]\n" +
$" (_ansi blue)template types(_ansi reset)\t - Show template categories\n" +
$" (_ansi blue)template show <name>(_ansi reset)\t\t - Show template details\n" +
$" (_ansi blue)template apply <name> <infra>(_ansi reset)\t - Apply to infrastructure\n" +
$" (_ansi blue)template validate <infra>(_ansi reset)\t - Validate template usage\n\n" +
$"(_ansi default_dimmed)💡 Config commands use active workspace if name not provided\n" +
$" Example: provisioning workspace config show --format json(_ansi reset)\n"
)
}
# Stubs for remaining categories (preserved from original for continuity)
def help-platform [] { "" }
def help-setup [] { "" }
def help-concepts [] { "" }
def help-guides [] { "" }
def help-authentication [] { "" }
def help-mfa [] { "" }
def help-plugins [] { "" }
def help-utilities [] { "" }
def help-tools [] { "" }
def help-diagnostics [] { "" }
def help-integrations [] { "" }
def help-vm [] { "" }