refactor: Migrate billing and config commands to uiContext with error handling and simplified output

- Update HandleBilling to accept CLIConfig, return error, and use uiContext for all output
- Update HandleConfig to accept CLIConfig, return error, and use uiContext for all output
- Replace manual colorizer/icon initialization with uiContext helper methods
- Simplify error handling with uiContext.errorln, warn, success, info, muted methods
- Replace direct table creation with uiContext.newTable()
This commit is contained in:
nutcas3
2026-04-17 16:26:43 +03:00
parent 5e70eac501
commit a32b933fbf
9 changed files with 904 additions and 1173 deletions
+44 -99
View File
@@ -2,130 +2,75 @@ package commands
import (
"fmt"
"github.com/nutcas3/telecom-platform/apps/cli/internal/types"
)
// Enhanced billing command handlers
// HandleBillingEnhanced delegates to the UI + API-connected billing handler.
func HandleBillingEnhanced(args []string, config *types.CLIConfig) error {
if len(args) == 0 {
fmt.Println("Enhanced Billing Management")
fmt.Println("Usage: telecom-cli billing <command> [options]")
fmt.Println()
fmt.Println("Available commands:")
fmt.Println(" invoices - Invoice management")
fmt.Println(" payments - Payment management")
fmt.Println(" reports - Financial reports")
fmt.Println(" settings - Billing settings")
return nil
}
command := args[0]
fmt.Printf("Billing command: %s (Profile: %s)\n", command, config.Profile)
fmt.Println("Billing operations coming soon...")
return nil
return HandleBilling(args, config)
}
// Enhanced monitoring command handlers
// HandleMonitoringEnhanced delegates to the UI + API-connected monitoring handler.
func HandleMonitoringEnhanced(args []string, config *types.CLIConfig) error {
if len(args) == 0 {
fmt.Println("Enhanced Monitoring Management")
fmt.Println("Usage: telecom-cli monitoring <command> [options]")
fmt.Println()
fmt.Println("Available commands:")
fmt.Println(" overview - System overview")
fmt.Println(" metrics - System metrics")
fmt.Println(" alerts - Alert management")
fmt.Println(" logs - Log management")
fmt.Println(" health - Health checks")
return nil
}
command := args[0]
fmt.Printf("Monitoring command: %s (Profile: %s)\n", command, config.Profile)
fmt.Println("Monitoring operations coming soon...")
return nil
return HandleMonitoring(args, config)
}
// Enhanced config command handlers
// HandleConfigEnhanced delegates to the UI + API-connected config handler.
func HandleConfigEnhanced(args []string, config *types.CLIConfig) error {
if len(args) == 0 {
fmt.Println("Enhanced Configuration Management")
fmt.Println("Usage: telecom-cli config <command> [options]")
fmt.Println()
fmt.Println("Available commands:")
fmt.Println(" show - Show configuration")
fmt.Println(" get <key> - Get config value")
fmt.Println(" set <key> <value> - Set config value")
fmt.Println(" profiles - Profile management")
fmt.Println(" secrets - Secret management")
return nil
}
command := args[0]
fmt.Printf("Config command: %s (Profile: %s)\n", command, config.Profile)
fmt.Println("Configuration operations coming soon...")
return nil
return HandleConfig(args, config)
}
// Enhanced deploy command handlers
// HandleDeployEnhanced delegates to the UI + API-connected deploy handler.
func HandleDeployEnhanced(args []string, config *types.CLIConfig) error {
if len(args) == 0 {
fmt.Println("Enhanced Deployment Management")
fmt.Println("Usage: telecom-cli deploy <command> [options]")
fmt.Println()
fmt.Println("Available commands:")
fmt.Println(" status - Deployment status")
fmt.Println(" start <env> - Start deployment")
fmt.Println(" stop <env> - Stop deployment")
fmt.Println(" rollback <version> - Rollback deployment")
fmt.Println(" environments - Environment management")
return nil
}
command := args[0]
fmt.Printf("Deploy command: %s (Profile: %s)\n", command, config.Profile)
fmt.Println("Deployment operations coming soon...")
return nil
return HandleDeploy(args, config)
}
// Enhanced plugins command handlers
// HandlePluginsEnhanced is a UI-styled stub for plugin management.
func HandlePluginsEnhanced(args []string, config *types.CLIConfig) error {
u := newUIContext(config)
u.header("Plugin Management")
if len(args) == 0 {
fmt.Println("Enhanced Plugin Management")
fmt.Println("Usage: telecom-cli plugins <command> [options]")
fmt.Println()
fmt.Println("Available commands:")
fmt.Println(" list - List plugins")
fmt.Println(" show <name> - Show plugin info")
fmt.Println(" install <name> - Install plugin")
fmt.Println(" uninstall <name> - Uninstall plugin")
fmt.Println(" enable <name> - Enable plugin")
fmt.Println(" disable <name> - Disable plugin")
t := u.newTable()
t.AddColumn("Command", 18, "left")
t.AddColumn("Description", 40, "left")
t.AddRow("list", "List plugins")
t.AddRow("show <name>", "Show plugin info")
t.AddRow("install <name>", "Install plugin")
t.AddRow("uninstall <name>", "Uninstall plugin")
t.AddRow("enable <name>", "Enable plugin")
t.AddRow("disable <name>", "Disable plugin")
fmt.Println(t.Render())
return nil
}
command := args[0]
fmt.Printf("Plugin command: %s (Profile: %s)\n", command, config.Profile)
fmt.Println("Plugin operations coming soon...")
u.info("Plugin command: " + args[0] + " (profile: " + safeProfile(config) + ")")
u.muted("Plugin operations are not yet wired to the API.")
return nil
}
// Enhanced automation command handlers
// HandleAutomationEnhanced is a UI-styled stub for automation.
func HandleAutomationEnhanced(args []string, config *types.CLIConfig) error {
u := newUIContext(config)
u.header("Automation Management")
if len(args) == 0 {
fmt.Println("Enhanced Automation Management")
fmt.Println("Usage: telecom-cli automation <command> [options]")
fmt.Println()
fmt.Println("Available commands:")
fmt.Println(" scripts - Script management")
fmt.Println(" workflows - Workflow management")
fmt.Println(" schedules - Schedule management")
fmt.Println(" jobs - Job management")
t := u.newTable()
t.AddColumn("Command", 18, "left")
t.AddColumn("Description", 40, "left")
t.AddRow("scripts", "Script management")
t.AddRow("workflows", "Workflow management")
t.AddRow("schedules", "Schedule management")
t.AddRow("jobs", "Job management")
fmt.Println(t.Render())
return nil
}
command := args[0]
fmt.Printf("Automation command: %s (Profile: %s)\n", command, config.Profile)
fmt.Println("Automation operations coming soon...")
u.info("Automation command: " + args[0] + " (profile: " + safeProfile(config) + ")")
u.muted("Automation operations are not yet wired to the API.")
return nil
}
func safeProfile(cfg *types.CLIConfig) string {
if cfg == nil || cfg.Profile == "" {
return "default"
}
return cfg.Profile
}