Files
telecom-platform/apps/cli/internal/commands/services.go
T
nutcas3 6c31f02b24 feat: Add basic services and subscribers command handlers with list, status, and CRUD operations
- Add HandleServices with command routing: list, status, restart, logs
- Add showServicesHelp with command descriptions and usage examples
- Add listServices to display services table with status, version, and uptime
- Add showServiceStatus to display service details with CPU/memory usage and last restart
- Add restartService to restart specified service
- Add showServiceLogs to display recent service
2026-04-17 16:05:53 +03:00

94 lines
2.6 KiB
Go

package commands
import (
"fmt"
)
func HandleServices(args []string) {
if len(args) == 0 {
showServicesHelp()
return
}
command := args[0]
switch command {
case "list":
listServices()
case "status":
showServiceStatus(args[1:])
case "restart":
restartService(args[1:])
case "logs":
showServiceLogs(args[1:])
default:
fmt.Printf("Unknown services command: %s\n", command)
showServicesHelp()
}
}
func showServicesHelp() {
fmt.Println("Service Management")
fmt.Println("Usage: telecom-cli services <command> [options]")
fmt.Println("\nAvailable commands:")
fmt.Println(" list - List all services")
fmt.Println(" status <service> - Show service status")
fmt.Println(" restart <service> - Restart a service")
fmt.Println(" logs <service> - Show service logs")
}
func listServices() {
fmt.Println("Platform Services:")
fmt.Println("Service Status Version Uptime")
fmt.Println("----------------------------------------------------")
fmt.Println("api-server Running v1.0.0 2h15m")
fmt.Println("charging-engine Running v1.0.0 2h15m")
fmt.Println("packet-gateway Running v1.0.0 2h15m")
fmt.Println("web-dashboard Running v1.0.0 2h15m")
fmt.Println("prometheus Running v2.45.0 2h15m")
fmt.Println("grafana Running v9.5.2 2h15m")
}
func showServiceStatus(args []string) {
if len(args) < 1 {
fmt.Println("Error: Service name is required")
fmt.Println("Usage: telecom-cli services status <service>")
return
}
service := args[0]
fmt.Printf("Service Status: %s\n", service)
fmt.Println("Status: Running")
fmt.Println("Version: v1.0.0")
fmt.Println("Uptime: 2h15m")
fmt.Println("CPU Usage: 45%")
fmt.Println("Memory Usage: 256MB")
fmt.Println("Last Restart: 2024-01-15 14:30:00")
}
func restartService(args []string) {
if len(args) < 1 {
fmt.Println("Error: Service name is required")
fmt.Println("Usage: telecom-cli services restart <service>")
return
}
service := args[0]
fmt.Printf("Restarting service: %s\n", service)
fmt.Println("Service restarted successfully!")
}
func showServiceLogs(args []string) {
if len(args) < 1 {
fmt.Println("Error: Service name is required")
fmt.Println("Usage: telecom-cli services logs <service>")
return
}
service := args[0]
fmt.Printf("Recent logs for %s:\n", service)
fmt.Println("2024-01-15 16:45:30 [INFO] Service started successfully")
fmt.Println("2024-01-15 16:45:35 [INFO] Database connection established")
fmt.Println("2024-01-15 16:45:40 [INFO] API server listening on port 8000")
fmt.Println("2024-01-15 16:45:45 [INFO] Health check passed")
}