This commit is contained in:
Dev
2025-09-13 03:03:35 +03:00
parent 67b170415b
commit d3416687c9
6 changed files with 69 additions and 172 deletions

View File

@@ -47,7 +47,7 @@ func runApply(cmd *cobra.Command, args []string) error {
}
// Detect distribution
fmt.Println("🔍 Detecting distribution...")
fmt.Println("Detecting distribution...")
distroInfo, err := distro.DetectDistribution()
if err != nil {
return fmt.Errorf("could not detect distribution: %w", err)
@@ -73,7 +73,7 @@ func runApply(cmd *cobra.Command, args []string) error {
configManager := config.NewConfigManager(distroInfo)
// First, find the fastest mirror
fmt.Printf("🔍 Finding fastest mirror for %s...\n", color.YellowString(distroInfo.Family))
fmt.Printf("Finding fastest mirror for %s...\n", color.YellowString(distroInfo.Family))
mirrorList := mirror.NewMirrorList(distroInfo.Family)
@@ -95,12 +95,12 @@ func runApply(cmd *cobra.Command, args []string) error {
return fmt.Errorf("no working mirrors found - your connection might be fucked")
}
fmt.Printf("🏆 Best mirror found: %s\n", color.GreenString(bestMirror.URL))
fmt.Printf("Speed: %.1f MB/s, Latency: %dms\n", bestMirror.Speed, bestMirror.Latency.Milliseconds())
fmt.Printf("Best mirror found: %s\n", color.GreenString(bestMirror.URL))
fmt.Printf("Speed: %.1f MB/s, Latency: %dms\n", bestMirror.Speed, bestMirror.Latency.Milliseconds())
// Ask for confirmation unless forced
if !force {
fmt.Printf("\n⚠️ This will modify %s\n", color.YellowString(configFile))
fmt.Printf("\nThis will modify %s\n", color.YellowString(configFile))
fmt.Print("Do you want to continue? [y/N]: ")
var response string
@@ -113,33 +113,33 @@ func runApply(cmd *cobra.Command, args []string) error {
}
// Create backup
fmt.Println("💾 Creating backup...")
fmt.Println("Creating backup...")
backupPath, err := configManager.BackupConfig()
if err != nil {
return fmt.Errorf("failed to create backup: %w", err)
}
fmt.Printf("Backup created: %s\n", color.GreenString(backupPath))
fmt.Printf("Backup created: %s\n", color.GreenString(backupPath))
// Apply the fastest mirror
fmt.Println("🔧 Applying fastest mirror configuration...")
fmt.Println("Applying fastest mirror configuration...")
err = configManager.ApplyMirror(bestMirror.URL)
if err != nil {
// Try to restore backup on failure
fmt.Printf("Failed to apply configuration: %v\n", err)
fmt.Printf("Failed to apply configuration: %v\n", err)
fmt.Println("<22> Attempting to restore backup...")
if restoreErr := configManager.RestoreBackup(backupPath); restoreErr != nil {
return fmt.Errorf("configuration failed AND backup restore failed: %v (original error: %v)", restoreErr, err)
}
fmt.Println("Backup restored successfully")
fmt.Println("Backup restored successfully")
return fmt.Errorf("configuration application failed, backup restored: %w", err)
}
fmt.Printf("🎉 Successfully applied fastest mirror!\n")
fmt.Printf("🔗 New mirror: %s\n", color.GreenString(bestMirror.URL))
fmt.Printf("Successfully applied fastest mirror!\n")
fmt.Printf("New mirror: %s\n", color.GreenString(bestMirror.URL))
fmt.Println()
fmt.Printf("💡 Don't forget to run your package manager's update command:\n")
fmt.Printf("Don't forget to run your package manager's update command:\n")
switch distroInfo.Family {
case "debian":