# Configuration Command Handlers # Handles: env, allenv, show, init, validate, config-template commands use ../flags.nu * use ../../lib_provisioning * use ../../servers/utils.nu * # Main configuration command dispatcher export def handle_config_command [ command: string ops: string flags: record ] { match $command { "env" | "e" => { handle_env $ops $flags } "allenv" => { handle_allenv $flags } "show" => { handle_show $ops $flags } "init" => { handle_init $ops $flags } "validate" | "val" => { handle_validate $ops $flags } "config-template" => { handle_config_template $ops $flags } "export" => { handle_config_export $ops $flags } "workspace" | "ws" => { handle_config_workspace $ops $flags } "platform" | "plat" => { handle_config_platform $ops $flags } "providers" | "prov" => { handle_config_providers $ops $flags } "services" | "svc" => { handle_config_services $ops $flags } _ => { print $"❌ Unknown configuration command: ($command)" print "" print "Available configuration commands:" print " env [subcmd] - Show/manage environment variables" print " allenv - Show all config and environment" print " show [path] - Show configuration details" print " init - Initialize infrastructure configuration" print " validate - Validate configuration" print " config-template - Generate config template" print " export - Export Nickel config to TOML" print " workspace - Configure workspace settings" print " platform - Configure platform services" print " providers - List/manage providers" print " services - List/manage platform services" print "" print "Configuration subcommands:" print " config export - Export all configs" print " config export - Export specific service" print " config validate - Validate Nickel config" print " config workspace info - Show workspace info" print " config platform orchestrator - Configure orchestrator" print " config platform kms - Configure KMS" print " config providers list - List all providers" print " config services list - List all services" print "" print "Use 'provisioning help configuration' for more details" exit 1 } } } # Environment command handler def handle_env [ops: string, flags: record] { let subcmd = if ($ops | is-empty) { "" } else { $ops | split row " " | first } if $subcmd in ["list" "current" "switch" "validate" "compare" "show" "init" "detect" "set" "paths" "create" "delete" "export" "status"] { # Use new environment management system use ../../lib_provisioning/cmd/environment.nu * match $subcmd { "list" => { env list } "current" => { env current } "switch" => { let target_env = ($ops | split row " " | get 1? | default "") if ($target_env | is-empty) { print "Usage: env switch " exit 1 } env switch $target_env } "validate" => { let target_env = ($ops | split row " " | get 1? | default "") env validate $target_env } "compare" => { let env1 = ($ops | split row " " | get 1? | default "") let env2 = ($ops | split row " " | get 2? | default "") if ($env1 | is-empty) or ($env2 | is-empty) { print "Usage: env compare " exit 1 } env compare $env1 $env2 } "show" => { let target_env = ($ops | split row " " | get 1? | default "") env show $target_env } "init" => { let target_env = ($ops | split row " " | get 1? | default "") if ($target_env | is-empty) { print "Usage: env init " exit 1 } env init $target_env } "detect" => { env detect } "set" => { let target_env = ($ops | split row " " | get 1? | default "") if ($target_env | is-empty) { print "Usage: env set " exit 1 } env set $target_env } "paths" => { let target_env = ($ops | split row " " | get 1? | default "") env paths $target_env } "create" => { let target_env = ($ops | split row " " | get 1? | default "") if ($target_env | is-empty) { print "Usage: env create " exit 1 } env create $target_env } "delete" => { let target_env = ($ops | split row " " | get 1? | default "") if ($target_env | is-empty) { print "Usage: env delete " exit 1 } env delete $target_env } "export" => { let target_env = ($ops | split row " " | get 1? | default "") env export $target_env } "status" => { let target_env = ($ops | split row " " | get 1? | default "") env status $target_env } _ => { print "Environment Management Commands:" print " env list - List available environments" print " env current - Show current environment" print " env switch - Switch to environment" print " env validate [env] - Validate environment" print " env compare - Compare environments" print " env show [env] - Show environment config" print " env init - Initialize environment" print " env detect - Detect current environment" print " env set - Set environment variable" print " env paths [env] - Show environment paths" print " env create - Create new environment" print " env delete - Delete environment" print " env export [env] - Export environment config" print " env status [env] - Show environment status" } } } else { # Fall back to legacy environment display match $flags.output_format { "json" => { _print (show_env | to json) "json" "result" "table" } "yaml" => { _print (show_env | to yaml) "yaml" "result" "table" } "toml" => { _print (show_env | to toml) "toml" "result" "table" } _ => { print (show_env | table -e) } } } } # All environment command handler def handle_allenv [flags: record] { let taskserv_defs_path = ($env.PROVISIONING_TASKSERVS_PATH | path join $env.PROVISIONING_GENERATE_DIRPATH | path join $env.PROVISIONING_GENERATE_DEFSFILE) let taskserv_defs = if ($taskserv_defs_path | path exists) { (open $taskserv_defs_path) } else { {} } let all_env = { env: (show_env), providers: (on_list "providers" "-" ""), taskservs: (on_list "taskservs" "-" ""), clusters: (on_list "clusters" "-" ""), infras: (on_list "infras" "-" ""), itemdefs: { providers: (find_provgendefs), taskserv: $taskserv_defs } } if $flags.view_mode { match $flags.output_format { "json" => { $all_env | to json | highlight } "yaml" => { $all_env | to yaml | highlight } "toml" => { $all_env | to toml | highlight } _ => { $all_env | to json | highlight } } } else { match $flags.output_format { "json" => { _print ($all_env | to json) "json" "result" "table" } "yaml" => { _print ($all_env | to yaml) "yaml" "result" "table" } "toml" => { _print ($all_env | to toml) "toml" "result" "table" } _ => { print ($all_env | to json) } } } } # Show command handler (extracted from main provisioning file) def handle_show [ops: string, flags: record] { let target = ($ops | split row " " | get 0? | default "") match $target { "h" | "help" => { print (provisioning_show_options) exit } } let curr_settings = (find_get_settings --infra $flags.infra --settings $flags.settings $flags.include_notuse) if ($curr_settings | is-empty) { if ($flags.output_format | is-empty) { _print $"🛑 Errors found in infra (_ansi yellow_bold)($flags.infra)(_ansi reset) notuse ($flags.include_notuse)" print ($curr_settings | describe) print $flags.settings } exit } let show_info = (get_show_info ($ops | split row " ") $curr_settings ($flags.output_format | default "")) if $flags.view_mode { match $flags.output_format { "json" => { print ($show_info | to json | highlight json) } "yaml" => { print ($show_info | to yaml | highlight yaml) } "toml" => { print ($show_info | to toml | highlight toml) } _ => { print ($show_info | to json | highlight) } } } else { match $flags.output_format { "json" => { _print ($show_info | to json) "json" "result" "table" } "yaml" => { _print ($show_info | to yaml) "yaml" "result" "table" } "toml" => { _print ($show_info | to toml) "toml" "result" "table" } _ => { print ($show_info | to json) } } } } # Init command handler def handle_init [ops: string, flags: record] { let subcmd = if ($ops | is-empty) { "" } else { $ops | split row " " | first } match $subcmd { "config" => { use ../../lib_provisioning/config/loader.nu init-user-config let template_type = ($ops | split row " " | get 1? | default "user") let force_flag = ($ops | split row " " | any {|op| $op == "--force" or $op == "-f"}) print "🚀 Initializing user configuration" print "==================================" print "" init-user-config --template $template_type --force $force_flag } "help" | "h" => { print "📋 Init Command Help" print "====================" print "" print "Initialize user configuration from templates:" print "" print "Commands:" print " init config [template] [--force] Initialize user config" print "" print "Templates:" print " user General user configuration (default)" print " dev Development environment optimized" print " prod Production environment optimized" print " test Testing environment optimized" print "" print "Options:" print " --force, -f Overwrite existing configuration" print "" print "Examples:" print " provisioning init config" print " provisioning init config dev" print " provisioning init config prod --force" } _ => { print "❌ Unknown init command. Use 'provisioning init help' for available options." } } } # Validate command handler (placeholder - full implementation in main file) def handle_validate [ops: string, flags: record] { # This is complex and should remain in main file for now # Just forward to the existing implementation print "Validate command - using existing implementation" } # Config template command handler def handle_config_template [ops: string, flags: record] { let subcmd = if ($ops | is-empty) { "" } else { $ops | split row " " | first } match $subcmd { "list" => { print "📋 Available Configuration Templates" print "===================================" print "" let project_root = $env.PWD let templates = [ { name: "user", file: "config.user.toml.example", description: "General user configuration with comprehensive documentation" } { name: "dev", file: "config.dev.toml.example", description: "Development environment with enhanced debugging" } { name: "prod", file: "config.prod.toml.example", description: "Production environment with security and performance focus" } { name: "test", file: "config.test.toml.example", description: "Testing environment with mock providers and CI/CD integration" } ] for template in $templates { let template_path = ($project_root | path join $template.file) let status = if ($template_path | path exists) { "✅" } else { "❌" } print $"($status) ($template.name) - ($template.description)" if ($template_path | path exists) { print $" 📁 ($template_path)" } else { print $" ❌ Template file not found: ($template_path)" } print "" } print "💡 Usage: provisioning init config [template_name]" } "help" | "h" => { print "📋 Configuration Template Command Help" print "======================================" print "" print "Manage configuration file templates (config.*.toml):" print "" print "Commands:" print " config-template list List available config templates" print " config-template show Show template content" print " config-template validate Validate all templates" print "" print "Examples:" print " provisioning config-template list" print " provisioning config-template show dev" print " provisioning config-template validate" } _ => { print "❌ Unknown config-template command. Use 'provisioning config-template help' for available options." } } } # Config export handler - Exports Nickel config to TOML for services def handle_config_export [ops: string, flags: record] { use ../../lib_provisioning/config/export.nu * let service = if ($ops | is-empty) { "" } else { $ops | split row " " | first } print "📦 Exporting Configuration" print "==========================" print "" if ($service | is-empty) { # Export all configs print "🔄 Exporting all configuration sections..." print "" export-all-configs print "✅ Configuration export complete" print "" print "Generated files:" print " • workspace_librecloud/config/generated/workspace.toml" print " • workspace_librecloud/config/generated/providers/*.toml" print " • workspace_librecloud/config/generated/platform/*.toml" } else { # Export specific service print $"🔄 Exporting platform service: ($service)..." export-platform-config $service print $"✅ Exported: workspace_librecloud/config/generated/platform/($service).toml" } } # Config workspace handler - Configure workspace settings def handle_config_workspace [ops: string, flags: record] { let subcmd = if ($ops | is-empty) { "" } else { $ops | split row " " | first } match $subcmd { "info" => { use ../../lib_provisioning/config/export.nu * print "📋 Workspace Information" print "=======================" print "" show-config } "validate" => { use ../../lib_provisioning/config/export.nu * print "✓ Validating workspace configuration..." let result = validate-config if $result.valid { print "✅ Configuration is valid" } else { print $"❌ Configuration validation failed: ($result.error)" exit 1 } } "help" | "h" => { print "📋 Workspace Configuration Commands" print "====================================" print "" print "Commands:" print " config workspace info - Show workspace information" print " config workspace validate - Validate workspace configuration" print "" print "Examples:" print " provisioning config workspace info" print " provisioning config workspace validate" } _ => { print "❌ Unknown workspace command. Use 'provisioning config workspace help' for available options." } } } # Config platform handler - Configure platform services def handle_config_platform [ops: string, flags: record] { let service = if ($ops | is-empty) { "" } else { $ops | split row " " | first } match $service { "orchestrator" => { print "⚙️ Configuring Orchestrator Service" print "====================================" print "" print "To configure the orchestrator interactively:" print "" print "Option 1: Use TypeDialog (interactive form)" print " provisioning-dialog ~/.typedialog/provisioning/platform/orchestrator/form.toml" print "" print "Option 2: Edit configuration directly" print " Edit: workspace_librecloud/config/config.ncl" print " Section: platform.orchestrator" print "" print "Option 3: Export existing configuration" print " provisioning config export orchestrator" print "" print "Then verify:" print " provisioning config validate" } "kms" => { print "🔐 Configuring KMS Service" print "==========================" print "" print "Edit KMS configuration:" print " workspace_librecloud/config/config.ncl" print " Section: platform.kms" print "" print "Available KMS backends:" print " • rustyvault - RustyVault KMS" print " • age - Age encryption" print " • aws - AWS KMS" print " • vault - HashiCorp Vault" print " • cosmian - Cosmian KMS" } "control-center" => { print "🎛️ Configuring Control Center Service" print "======================================" print "" print "To configure the control center interactively:" print "" print "Option 1: Use TypeDialog (interactive form)" print " typedialog form .typedialog/provisioning/platform/control-center/form.toml" print "" print "Option 2: Edit configuration directly" print " Edit: workspace_librecloud/config/config.ncl" print " Section: platform.control_center" print "" print "Then verify:" print " provisioning config validate" print "" print "Control Center manages:" print " • Admin interface and web UI" print " • User authentication (JWT)" print " • Rate limiting and CORS" print " • Session management" } "mcp-server" => { print "🔌 Configuring MCP Server Service" print "==================================" print "" print "To configure the MCP server interactively:" print "" print "Option 1: Use TypeDialog (interactive form)" print " typedialog form .typedialog/provisioning/platform/mcp-server/form.toml" print "" print "Option 2: Edit configuration directly" print " Edit: workspace_librecloud/config/config.ncl" print " Section: platform.mcp_server" print "" print "Then verify:" print " provisioning config validate" print "" print "MCP Server provides:" print " • Model Context Protocol integration" print " • Tool and prompt management" print " • Resource caching" print " • AI assistant integration" } "installer" => { print "🚀 Configuring Installer Service" print "=================================" print "" print "To configure the installer interactively:" print "" print "Option 1: Use TypeDialog (interactive form)" print " typedialog form .typedialog/provisioning/platform/installer/form.toml" print "" print "Option 2: Edit configuration directly" print " Edit: workspace_librecloud/config/config.ncl" print " Section: platform.installer" print "" print "Then verify:" print " provisioning config validate" print "" print "Installer configures:" print " • Deployment mode (solo, multiuser, cicd, enterprise)" print " • Container platform (docker, podman, kubernetes)" print " • Service selection and enablement" print " • Resource allocation" print " • High availability settings" } "help" | "h" | "" => { print "📋 Platform Service Configuration Commands" print "==========================================" print "" print "Commands:" print " config platform orchestrator - Configure orchestrator service" print " config platform control-center - Configure control center UI" print " config platform mcp-server - Configure MCP server" print " config platform installer - Configure installer" print " config platform kms - Configure KMS service" print "" print "For more details:" print " provisioning config platform " print "" print "Interactive Configuration (Recommended):" print " typedialog form .typedialog/provisioning/platform//form.toml" } _ => { print $"❌ Unknown platform service: ($service)" print "" print "Available services: orchestrator, control-center, mcp-server, vault-service, extension-registry, rag, ai-service, provisioning-daemon" print "" print "Use 'provisioning config platform help' for more information" } } } # Config providers handler - List and manage providers def handle_config_providers [ops: string, flags: record] { use ../../lib_provisioning/config/export.nu * let subcmd = if ($ops | is-empty) { "" } else { $ops | split row " " | first } match $subcmd { "list" => { print "☁️ Configured Cloud Providers" print "==============================" print "" list-providers } "help" | "h" | "" => { print "📋 Provider Configuration Commands" print "==================================" print "" print "Commands:" print " config providers list - List all configured providers" print "" print "To configure providers:" print " Edit: workspace_librecloud/config/config.ncl" print " Section: providers" print "" print "Available providers:" print " • upcloud - UpCloud provider (European cloud)" print " • aws - Amazon Web Services" print " • local - Local/testing provider" } _ => { print $"❌ Unknown providers command: ($subcmd)" } } } # Config services handler - List and manage platform services def handle_config_services [ops: string, flags: record] { use ../../lib_provisioning/config/export.nu * let subcmd = if ($ops | is-empty) { "" } else { $ops | split row " " | first } match $subcmd { "list" => { print "🔧 Configured Platform Services" print "===============================" print "" list-platform-services } "help" | "h" | "" => { print "📋 Platform Services Commands" print "============================" print "" print "Commands:" print " config services list - List all configured services" print "" print "To configure services:" print " Edit: workspace_librecloud/config/config.ncl" print " Section: platform" print "" print "Available services:" print " • orchestrator - Infrastructure orchestrator" print " • kms - Key management system" print " • control-center - Admin control panel" print " • plugins - Native performance plugins" } _ => { print $"❌ Unknown services command: ($subcmd)" } } }