From c4b61f5c05951587bc7c2aa4c3a437a8a218de94 Mon Sep 17 00:00:00 2001 From: nutcas3 Date: Fri, 17 Apr 2026 16:02:05 +0300 Subject: [PATCH] feat: Add enhanced CLI with command routing and global configuration management - Add EnhancedCLI with CLIConfig for API endpoint, token, profile, verbose, no-color, and theme settings - Add command routing: dashboard, subscribers, services, billing, monitoring, config, deploy, plugins, automation - Add runDashboard to launch Bubble Tea dashboard interface - Add showHelp with command descriptions and global options documentation - Add parseConfig to parse global flags: --endpoint, --token, --profile --- apps/cli/internal/app/enhanced_root.go | 137 +++++++++++++++++++++++++ 1 file changed, 137 insertions(+) create mode 100644 apps/cli/internal/app/enhanced_root.go diff --git a/apps/cli/internal/app/enhanced_root.go b/apps/cli/internal/app/enhanced_root.go new file mode 100644 index 0000000..2d5e3ce --- /dev/null +++ b/apps/cli/internal/app/enhanced_root.go @@ -0,0 +1,137 @@ +package app + +import ( + "fmt" + "os" + + tea "github.com/charmbracelet/bubbletea" + "github.com/nutcas3/telecom-platform/apps/cli/internal/commands" + "github.com/nutcas3/telecom-platform/apps/cli/internal/types" +) + +type EnhancedCLI struct { + config *types.CLIConfig +} + +func NewEnhancedCLI() *EnhancedCLI { + return &EnhancedCLI{ + config: &types.CLIConfig{ + APIEndpoint: "http://localhost:8000", + APIToken: "", + Profile: "default", + Verbose: false, + NoColor: false, + Theme: "default", + }, + } +} + +func (cli *EnhancedCLI) Run(args []string) error { + if len(args) < 2 { + cli.showHelp() + return nil + } + + command := args[1] + commandArgs := args[2:] + + switch command { + case "dashboard": + return cli.runDashboard() + case "subscribers": + return commands.HandleSubscribersEnhanced(commandArgs, cli.config) + case "services": + return commands.HandleServicesEnhanced(commandArgs, cli.config) + case "billing": + return commands.HandleBillingEnhanced(commandArgs, cli.config) + case "monitoring": + return commands.HandleMonitoringEnhanced(commandArgs, cli.config) + case "config": + return commands.HandleConfigEnhanced(commandArgs, cli.config) + case "deploy": + return commands.HandleDeployEnhanced(commandArgs, cli.config) + case "plugins": + return commands.HandlePluginsEnhanced(commandArgs, cli.config) + case "automation": + return commands.HandleAutomationEnhanced(commandArgs, cli.config) + default: + fmt.Printf("Unknown command: %s\n", command) + cli.showHelp() + return fmt.Errorf("unknown command: %s", command) + } +} + +func (cli *EnhancedCLI) runDashboard() error { + p := tea.NewProgram(NewDashboard()) + if _, err := p.Run(); err != nil { + return fmt.Errorf("error running dashboard: %w", err) + } + return nil +} + +func (cli *EnhancedCLI) showHelp() { + fmt.Println("Telecom Platform CLI - Enhanced") + fmt.Println("Usage: telecom-cli [options]") + fmt.Println() + fmt.Println("Available commands:") + fmt.Println(" dashboard - Interactive dashboard for platform overview") + fmt.Println(" subscribers - Subscriber management") + fmt.Println(" services - Service management") + fmt.Println(" billing - Billing and invoice management") + fmt.Println(" monitoring - Monitoring and metrics") + fmt.Println(" config - Configuration management") + fmt.Println(" deploy - Deployment management") + fmt.Println(" plugins - Plugin management") + fmt.Println(" automation - Automation and scripting") + fmt.Println() + fmt.Println("Global options:") + fmt.Println(" --endpoint API endpoint (default: http://localhost:8000)") + fmt.Println(" --token API authentication token") + fmt.Println(" --profile Configuration profile") + fmt.Println(" --verbose Enable verbose output") + fmt.Println(" --no-color Disable color output") + fmt.Println() + fmt.Println("Use 'telecom-cli --help' for more information") +} + +func (cli *EnhancedCLI) parseConfig(args []string) error { + for i := 0; i < len(args); i++ { + switch args[i] { + case "--endpoint": + if i+1 < len(args) { + cli.config.APIEndpoint = args[i+1] + i++ + } + case "--token": + if i+1 < len(args) { + cli.config.APIToken = args[i+1] + i++ + } + case "--profile": + if i+1 < len(args) { + cli.config.Profile = args[i+1] + i++ + } + case "--verbose": + cli.config.Verbose = true + case "--no-color": + cli.config.NoColor = true + } + } + return nil +} + +func Main() { + cli := NewEnhancedCLI() + + // Parse global options + if err := cli.parseConfig(os.Args); err != nil { + fmt.Fprintf(os.Stderr, "Error parsing options: %v\n", err) + os.Exit(1) + } + + if err := cli.Run(os.Args); err != nil { + fmt.Fprintf(os.Stderr, "Error: %v\n", err) + os.Exit(1) + } +}