debian-forge-composer/internal/advanced/advanced_cli.go
robojerk 4eeaa43c39
Some checks failed
Tests / 🛃 Unit tests (push) Failing after 13s
Tests / 🗄 DB tests (push) Failing after 19s
Tests / 🐍 Lint python scripts (push) Failing after 1s
Tests / ⌨ Golang Lint (push) Failing after 1s
Tests / 📦 Packit config lint (push) Failing after 1s
Tests / 🔍 Check source preparation (push) Failing after 1s
Tests / 🔍 Check for valid snapshot urls (push) Failing after 1s
Tests / 🔍 Check for missing or unused runner repos (push) Failing after 1s
Tests / 🐚 Shellcheck (push) Failing after 1s
Tests / 📦 RPMlint (push) Failing after 1s
Tests / Gitlab CI trigger helper (push) Failing after 1s
Tests / 🎀 kube-linter (push) Failing after 1s
Tests / 🧹 cloud-cleaner-is-enabled (push) Successful in 3s
Tests / 🔍 Check spec file osbuild/images dependencies (push) Failing after 1s
did stuff
2025-08-26 10:34:42 -07:00

683 lines
21 KiB
Go

package advanced
import (
"fmt"
"strconv"
"time"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
)
// AdvancedCLI provides command-line interface for advanced features management
type AdvancedCLI struct {
manager *AdvancedManager
configPath string
logger *logrus.Logger
}
// NewAdvancedCLI creates a new advanced features CLI
func NewAdvancedCLI(configPath string, logger *logrus.Logger) *AdvancedCLI {
return &AdvancedCLI{
configPath: configPath,
logger: logger,
}
}
// CreateRootCommand creates the root advanced features command
func (cli *AdvancedCLI) CreateRootCommand() *cobra.Command {
rootCmd := &cobra.Command{
Use: "advanced",
Short: "Debian Forge Advanced Features",
Long: "Manage multi-architecture support, advanced customization, and future-proofing",
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
return cli.initializeManager()
},
}
// Add subcommands
rootCmd.AddCommand(cli.createMultiArchCommand())
rootCmd.AddCommand(cli.createCustomizationCommand())
rootCmd.AddCommand(cli.createFutureProofCommand())
rootCmd.AddCommand(cli.createConfigCommand())
rootCmd.AddCommand(cli.createStatusCommand())
return rootCmd
}
// initializeManager initializes the advanced features manager
func (cli *AdvancedCLI) initializeManager() error {
// Load configuration
config, err := LoadAdvancedConfig(cli.configPath)
if err != nil {
return fmt.Errorf("failed to load configuration: %w", err)
}
// Validate configuration
configManager := &AdvancedConfigManager{configPath: cli.configPath, config: config}
if err := configManager.ValidateConfig(); err != nil {
return fmt.Errorf("configuration validation failed: %w", err)
}
// Create advanced features manager
cli.manager = NewAdvancedManager(config, cli.logger)
return nil
}
// createMultiArchCommand creates the multi-architecture command
func (cli *AdvancedCLI) createMultiArchCommand() *cobra.Command {
multiArchCmd := &cobra.Command{
Use: "multiarch",
Short: "Manage multi-architecture support",
Long: "Build multi-architecture images and manage architecture-specific optimizations",
}
// Build multi-arch image subcommand
buildCmd := &cobra.Command{
Use: "build [architecture]",
Short: "Build multi-architecture image",
Long: "Build an image for a specific architecture",
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
return cli.buildMultiArchImage(args[0])
},
}
// List architectures subcommand
listArchsCmd := &cobra.Command{
Use: "list",
Short: "List supported architectures",
Long: "List all supported architectures and their status",
RunE: func(cmd *cobra.Command, args []string) error {
return cli.listArchitectures()
},
}
// List optimizations subcommand
listOptsCmd := &cobra.Command{
Use: "optimizations",
Short: "List architecture optimizations",
Long: "List all architecture-specific optimizations",
RunE: func(cmd *cobra.Command, args []string) error {
return cli.listOptimizations()
},
}
// List builders subcommand
listBuildersCmd := &cobra.Command{
Use: "builders",
Short: "List architecture builders",
Long: "List all architecture-specific builders",
RunE: func(cmd *cobra.Command, args []string) error {
return cli.listBuilders()
},
}
multiArchCmd.AddCommand(buildCmd, listArchsCmd, listOptsCmd, listBuildersCmd)
return multiArchCmd
}
// createCustomizationCommand creates the customization command
func (cli *AdvancedCLI) createCustomizationCommand() *cobra.Command {
customizationCmd := &cobra.Command{
Use: "customization",
Short: "Manage advanced customization",
Long: "Apply kernel configurations, hardware optimizations, and partitioning schemes",
}
// Kernel configuration subcommand
kernelCmd := &cobra.Command{
Use: "kernel [config] [target]",
Short: "Apply kernel configuration",
Long: "Apply a kernel configuration to a target path",
Args: cobra.ExactArgs(2),
RunE: func(cmd *cobra.Command, args []string) error {
return cli.applyKernelConfig(args[0], args[1])
},
}
// Hardware optimization subcommand
hardwareCmd := &cobra.Command{
Use: "hardware [optimization] [target]",
Short: "Apply hardware optimization",
Long: "Apply a hardware optimization to a target path",
Args: cobra.ExactArgs(2),
RunE: func(cmd *cobra.Command, args []string) error {
return cli.applyHardwareOptimization(args[0], args[1])
},
}
// List kernel configs subcommand
listKernelsCmd := &cobra.Command{
Use: "kernels",
Short: "List kernel configurations",
Long: "List all available kernel configurations",
RunE: func(cmd *cobra.Command, args []string) error {
return cli.listKernelConfigs()
},
}
// List hardware optimizations subcommand
listHardwareCmd := &cobra.Command{
Use: "hardware",
Short: "List hardware optimizations",
Long: "List all available hardware optimizations",
RunE: func(cmd *cobra.Command, args []string) error {
return cli.listHardwareOptimizations()
},
}
// List partitioning schemes subcommand
listPartitioningCmd := &cobra.Command{
Use: "partitioning",
Short: "List partitioning schemes",
Long: "List all available partitioning schemes",
RunE: func(cmd *cobra.Command, args []string) error {
return cli.listPartitioningSchemes()
},
}
// List bootloader configs subcommand
listBootloadersCmd := &cobra.Command{
Use: "bootloaders",
Short: "List bootloader configurations",
Long: "List all available bootloader configurations",
RunE: func(cmd *cobra.Command, args []string) error {
return cli.listBootloaderConfigs()
},
}
customizationCmd.AddCommand(kernelCmd, hardwareCmd, listKernelsCmd, listHardwareCmd, listPartitioningCmd, listBootloadersCmd)
return customizationCmd
}
// createFutureProofCommand creates the future-proofing command
func (cli *AdvancedCLI) createFutureProofCommand() *cobra.Command {
futureProofCmd := &cobra.Command{
Use: "futureproof",
Short: "Manage future-proofing",
Long: "Monitor emerging technologies, Debian versions, and upstream compatibility",
}
// Technology status subcommand
techStatusCmd := &cobra.Command{
Use: "technology [id]",
Short: "Show technology status",
Long: "Show status of an emerging technology",
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
return cli.showTechnologyStatus(args[0])
},
}
// Debian version status subcommand
debianStatusCmd := &cobra.Command{
Use: "debian [version]",
Short: "Show Debian version status",
Long: "Show status of a Debian version",
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
return cli.showDebianVersionStatus(args[0])
},
}
// Upstream compatibility subcommand
upstreamCmd := &cobra.Command{
Use: "upstream [component]",
Short: "Show upstream compatibility",
Long: "Show upstream compatibility status",
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
return cli.showUpstreamCompatibility(args[0])
},
}
// Technology roadmap subcommand
roadmapCmd := &cobra.Command{
Use: "roadmap [id]",
Short: "Show technology roadmap",
Long: "Show technology roadmap and milestones",
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
return cli.showTechnologyRoadmap(args[0])
},
}
// List technologies subcommand
listTechsCmd := &cobra.Command{
Use: "technologies",
Short: "List emerging technologies",
Long: "List all emerging technologies",
RunE: func(cmd *cobra.Command, args []string) error {
return cli.listEmergingTechnologies()
},
}
// List Debian versions subcommand
listDebianVersionsCmd := &cobra.Command{
Use: "debian-versions",
Short: "List Debian versions",
Long: "List all Debian versions and their status",
RunE: func(cmd *cobra.Command, args []string) error {
return cli.listDebianVersions()
},
}
futureProofCmd.AddCommand(techStatusCmd, debianStatusCmd, upstreamCmd, roadmapCmd, listTechsCmd, listDebianVersionsCmd)
return futureProofCmd
}
// createConfigCommand creates the configuration command
func (cli *AdvancedCLI) createConfigCommand() *cobra.Command {
configCmd := &cobra.Command{
Use: "config",
Short: "Manage advanced features configuration",
Long: "View and modify advanced features configuration",
}
// Show configuration subcommand
showCmd := &cobra.Command{
Use: "show",
Short: "Show current configuration",
Long: "Show current advanced features configuration",
RunE: func(cmd *cobra.Command, args []string) error {
return cli.showConfig()
},
}
// Update configuration subcommand
updateCmd := &cobra.Command{
Use: "update [key] [value]",
Short: "Update configuration",
Long: "Update a configuration value",
Args: cobra.ExactArgs(2),
RunE: func(cmd *cobra.Command, args []string) error {
return cli.updateConfig(args[0], args[1])
},
}
// Validate configuration subcommand
validateCmd := &cobra.Command{
Use: "validate",
Short: "Validate configuration",
Long: "Validate current configuration",
RunE: func(cmd *cobra.Command, args []string) error {
return cli.validateConfig()
},
}
configCmd.AddCommand(showCmd, updateCmd, validateCmd)
return configCmd
}
// createStatusCommand creates the status command
func (cli *AdvancedCLI) createStatusCommand() *cobra.Command {
statusCmd := &cobra.Command{
Use: "status",
Short: "Show advanced features status",
Long: "Show current status of advanced features systems",
RunE: func(cmd *cobra.Command, args []string) error {
return cli.showStatus()
},
}
return statusCmd
}
// Multi-architecture methods
func (cli *AdvancedCLI) buildMultiArchImage(archID string) error {
config := make(map[string]interface{})
if err := cli.manager.multiArch.BuildMultiArchImage(archID, config); err != nil {
return fmt.Errorf("multi-architecture image build failed: %w", err)
}
fmt.Printf("Multi-architecture image built successfully for: %s\n", archID)
return nil
}
func (cli *AdvancedCLI) listArchitectures() error {
fmt.Printf("Supported Architectures:\n")
fmt.Printf("========================\n")
for id, arch := range cli.manager.multiArch.architectures {
fmt.Printf(" %s:\n", id)
fmt.Printf(" Name: %s\n", arch.Name)
fmt.Printf(" Description: %s\n", arch.Description)
fmt.Printf(" Type: %s\n", arch.Type)
fmt.Printf(" Endianness: %s\n", arch.Endianness)
fmt.Printf(" Word Size: %d\n", arch.WordSize)
fmt.Printf(" Supported: %t\n", arch.Supported)
fmt.Printf(" Enabled: %t\n", arch.Enabled)
fmt.Printf("\n")
}
return nil
}
func (cli *AdvancedCLI) listOptimizations() error {
fmt.Printf("Architecture Optimizations:\n")
fmt.Printf("===========================\n")
for id, opt := range cli.manager.multiArch.optimizations {
fmt.Printf(" %s:\n", id)
fmt.Printf(" Name: %s\n", opt.Name)
fmt.Printf(" Description: %s\n", opt.Description)
fmt.Printf(" Architecture: %s\n", opt.ArchID)
fmt.Printf(" Type: %s\n", opt.Type)
fmt.Printf(" Parameters: %v\n", opt.Parameters)
fmt.Printf(" Enabled: %t\n", opt.Enabled)
fmt.Printf("\n")
}
return nil
}
func (cli *AdvancedCLI) listBuilders() error {
fmt.Printf("Architecture Builders:\n")
fmt.Printf("======================\n")
for id, builder := range cli.manager.multiArch.builders {
fmt.Printf(" %s:\n", id)
fmt.Printf(" Name: %s\n", builder.Name)
fmt.Printf(" Description: %s\n", builder.Description)
fmt.Printf(" Architecture: %s\n", builder.ArchID)
fmt.Printf(" Type: %s\n", builder.Type)
fmt.Printf(" Builder Path: %s\n", builder.BuilderPath)
fmt.Printf(" Config: %v\n", builder.Config)
fmt.Printf(" Enabled: %t\n", builder.Enabled)
fmt.Printf("\n")
}
return nil
}
// Customization methods
func (cli *AdvancedCLI) applyKernelConfig(configID string, targetPath string) error {
if err := cli.manager.customization.ApplyKernelConfig(configID, targetPath); err != nil {
return fmt.Errorf("kernel configuration application failed: %w", err)
}
fmt.Printf("Kernel configuration applied successfully: %s to %s\n", configID, targetPath)
return nil
}
func (cli *AdvancedCLI) applyHardwareOptimization(optID string, targetPath string) error {
if err := cli.manager.customization.ApplyHardwareOptimization(optID, targetPath); err != nil {
return fmt.Errorf("hardware optimization application failed: %w", err)
}
fmt.Printf("Hardware optimization applied successfully: %s to %s\n", optID, targetPath)
return nil
}
func (cli *AdvancedCLI) listKernelConfigs() error {
fmt.Printf("Kernel Configurations:\n")
fmt.Printf("======================\n")
for id, config := range cli.manager.customization.kernels {
fmt.Printf(" %s:\n", id)
fmt.Printf(" Name: %s\n", config.Name)
fmt.Printf(" Description: %s\n", config.Description)
fmt.Printf(" Version: %s\n", config.Version)
fmt.Printf(" Config Path: %s\n", config.ConfigPath)
fmt.Printf(" Modules: %v\n", config.Modules)
fmt.Printf(" Parameters: %v\n", config.Parameters)
fmt.Printf(" Enabled: %t\n", config.Enabled)
fmt.Printf("\n")
}
return nil
}
func (cli *AdvancedCLI) listHardwareOptimizations() error {
fmt.Printf("Hardware Optimizations:\n")
fmt.Printf("=======================\n")
for id, opt := range cli.manager.customization.hardware {
fmt.Printf(" %s:\n", id)
fmt.Printf(" Name: %s\n", opt.Name)
fmt.Printf(" Description: %s\n", opt.Description)
fmt.Printf(" Hardware: %s\n", opt.Hardware)
fmt.Printf(" Type: %s\n", opt.Type)
fmt.Printf(" Config: %v\n", opt.Config)
fmt.Printf(" Enabled: %t\n", opt.Enabled)
fmt.Printf("\n")
}
return nil
}
func (cli *AdvancedCLI) listPartitioningSchemes() error {
fmt.Printf("Partitioning Schemes:\n")
fmt.Printf("=====================\n")
for id, scheme := range cli.manager.customization.partitioning {
fmt.Printf(" %s:\n", id)
fmt.Printf(" Name: %s\n", scheme.Name)
fmt.Printf(" Description: %s\n", scheme.Description)
fmt.Printf(" Type: %s\n", scheme.Type)
fmt.Printf(" Layout: %s\n", scheme.Layout)
fmt.Printf(" Partitions: %d\n", len(scheme.Partitions))
fmt.Printf(" Enabled: %t\n", scheme.Enabled)
if len(scheme.Partitions) > 0 {
fmt.Printf(" Partition Details:\n")
for _, partition := range scheme.Partitions {
fmt.Printf(" %s: %s (%s) -> %s\n", partition.Name, partition.Size, partition.Format, partition.MountPoint)
}
}
fmt.Printf("\n")
}
return nil
}
func (cli *AdvancedCLI) listBootloaderConfigs() error {
fmt.Printf("Bootloader Configurations:\n")
fmt.Printf("==========================\n")
for id, config := range cli.manager.customization.bootloaders {
fmt.Printf(" %s:\n", id)
fmt.Printf(" Name: %s\n", config.Name)
fmt.Printf(" Description: %s\n", config.Description)
fmt.Printf(" Type: %s\n", config.Type)
fmt.Printf(" Config Path: %s\n", config.ConfigPath)
fmt.Printf(" Parameters: %v\n", config.Parameters)
fmt.Printf(" Timeout: %d\n", config.Timeout)
fmt.Printf(" Enabled: %t\n", config.Enabled)
fmt.Printf("\n")
}
return nil
}
// Future-proofing methods
func (cli *AdvancedCLI) showTechnologyStatus(techID string) error {
tech, err := cli.manager.futureProof.GetTechnologyStatus(techID)
if err != nil {
return fmt.Errorf("failed to get technology status: %w", err)
}
fmt.Printf("Technology: %s\n", tech.Name)
fmt.Printf("============\n")
fmt.Printf(" Description: %s\n", tech.Description)
fmt.Printf(" Category: %s\n", tech.Category)
fmt.Printf(" Status: %s\n", tech.Status)
fmt.Printf(" Maturity: %s\n", tech.Maturity)
fmt.Printf(" Integration: %v\n", tech.Integration)
fmt.Printf(" Enabled: %t\n", tech.Enabled)
return nil
}
func (cli *AdvancedCLI) showDebianVersionStatus(versionID string) error {
version, err := cli.manager.futureProof.GetDebianVersionStatus(versionID)
if err != nil {
return fmt.Errorf("failed to get Debian version status: %w", err)
}
fmt.Printf("Debian Version: %s\n", version.Name)
fmt.Printf("================\n")
fmt.Printf(" Version: %s\n", version.Version)
fmt.Printf(" Status: %s\n", version.Status)
fmt.Printf(" Release Date: %v\n", version.ReleaseDate)
fmt.Printf(" End of Life: %v\n", version.EndOfLife)
fmt.Printf(" Features: %v\n", version.Features)
fmt.Printf(" Enabled: %t\n", version.Enabled)
return nil
}
func (cli *AdvancedCLI) showUpstreamCompatibility(componentID string) error {
compat, err := cli.manager.futureProof.GetUpstreamCompatibility(componentID)
if err != nil {
return fmt.Errorf("failed to get upstream compatibility: %w", err)
}
fmt.Printf("Upstream Compatibility: %s\n", compat.Component)
fmt.Printf("========================\n")
fmt.Printf(" Version: %s\n", compat.Version)
fmt.Printf(" Status: %s\n", compat.Status)
fmt.Printf(" Compatibility: %s\n", compat.Compatibility)
fmt.Printf(" Migration: %v\n", compat.Migration)
fmt.Printf(" Enabled: %t\n", compat.Enabled)
return nil
}
func (cli *AdvancedCLI) showTechnologyRoadmap(roadmapID string) error {
roadmap, err := cli.manager.futureProof.GetTechnologyRoadmap(roadmapID)
if err != nil {
return fmt.Errorf("failed to get technology roadmap: %w", err)
}
fmt.Printf("Technology Roadmap: %s\n", roadmap.Name)
fmt.Printf("====================\n")
fmt.Printf(" Description: %s\n", roadmap.Description)
fmt.Printf(" Timeline: %s\n", roadmap.Timeline)
fmt.Printf(" Status: %s\n", roadmap.Status)
fmt.Printf(" Milestones: %d\n", len(roadmap.Milestones))
fmt.Printf(" Enabled: %t\n", roadmap.Enabled)
if len(roadmap.Milestones) > 0 {
fmt.Printf("\n Milestones:\n")
for _, milestone := range roadmap.Milestones {
fmt.Printf(" %s: %s (%s) - %d%%\n", milestone.Name, milestone.Description, milestone.Status, milestone.Progress)
}
}
return nil
}
func (cli *AdvancedCLI) listEmergingTechnologies() error {
fmt.Printf("Emerging Technologies:\n")
fmt.Printf("======================\n")
for id, tech := range cli.manager.futureProof.technologies {
fmt.Printf(" %s: %s (%s)\n", id, tech.Name, tech.Status)
}
return nil
}
func (cli *AdvancedCLI) listDebianVersions() error {
fmt.Printf("Debian Versions:\n")
fmt.Printf("================\n")
for id, version := range cli.manager.futureProof.debianVersions {
fmt.Printf(" %s: %s %s (%s)\n", id, version.Name, version.Version, version.Status)
}
return nil
}
// Configuration methods
func (cli *AdvancedCLI) showConfig() error {
if cli.manager.config == nil {
return fmt.Errorf("no configuration loaded")
}
fmt.Printf("Advanced Features Configuration:\n")
fmt.Printf("================================\n")
fmt.Printf(" Enabled: %t\n", cli.manager.config.Enabled)
fmt.Printf(" Multi-Architecture: %t\n", cli.manager.config.MultiArch)
fmt.Printf(" Customization: %t\n", cli.manager.config.Customization)
fmt.Printf(" Future-Proofing: %t\n", cli.manager.config.FutureProof)
if len(cli.manager.config.Metadata) > 0 {
fmt.Printf(" Metadata:\n")
for key, value := range cli.manager.config.Metadata {
fmt.Printf(" %s: %s\n", key, value)
}
}
return nil
}
func (cli *AdvancedCLI) updateConfig(key string, value string) error {
configManager := &AdvancedConfigManager{configPath: cli.configPath, config: cli.manager.config}
updates := make(map[string]interface{})
// Parse value based on key type
switch key {
case "enabled", "multi_arch", "customization", "future_proof":
if boolVal, err := strconv.ParseBool(value); err == nil {
updates[key] = boolVal
} else {
return fmt.Errorf("invalid boolean value for %s: %s", key, value)
}
default:
return fmt.Errorf("unknown configuration key: %s", key)
}
if err := configManager.UpdateConfig(updates); err != nil {
return fmt.Errorf("failed to update configuration: %w", err)
}
fmt.Printf("Configuration updated: %s = %s\n", key, value)
return nil
}
func (cli *AdvancedCLI) validateConfig() error {
configManager := &AdvancedConfigManager{configPath: cli.configPath, config: cli.manager.config}
if err := configManager.ValidateConfig(); err != nil {
return fmt.Errorf("configuration validation failed: %w", err)
}
fmt.Printf("Configuration validation passed\n")
return nil
}
// Status methods
func (cli *AdvancedCLI) showStatus() error {
fmt.Printf("Advanced Features System Status:\n")
fmt.Printf("================================\n")
// Multi-architecture system status
fmt.Printf("Multi-Architecture System:\n")
fmt.Printf(" Status: Active\n")
fmt.Printf(" Architectures: %d\n", len(cli.manager.multiArch.architectures))
fmt.Printf(" Optimizations: %d\n", len(cli.manager.multiArch.optimizations))
fmt.Printf(" Builders: %d\n", len(cli.manager.multiArch.builders))
// Customization system status
fmt.Printf("\nCustomization System:\n")
fmt.Printf(" Status: Active\n")
fmt.Printf(" Kernel Configs: %d\n", len(cli.manager.customization.kernels))
fmt.Printf(" Hardware Optimizations: %d\n", len(cli.manager.customization.hardware))
fmt.Printf(" Partitioning Schemes: %d\n", len(cli.manager.customization.partitioning))
fmt.Printf(" Bootloader Configs: %d\n", len(cli.manager.customization.bootloaders))
// Future-proofing system status
fmt.Printf("\nFuture-Proofing System:\n")
fmt.Printf(" Status: Active\n")
fmt.Printf(" Emerging Technologies: %d\n", len(cli.manager.futureProof.technologies))
fmt.Printf(" Debian Versions: %d\n", len(cli.manager.futureProof.debianVersions))
fmt.Printf(" Upstream Compatibility: %d\n", len(cli.manager.futureProof.upstream))
fmt.Printf(" Technology Roadmaps: %d\n", len(cli.manager.futureProof.roadmap))
return nil
}