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":

View File

@@ -33,21 +33,21 @@ This command will:
func runFind(cmd *cobra.Command, args []string) error {
// Detect distribution
fmt.Println(color.CyanString("🔍 Detecting your Linux distribution..."))
fmt.Println(color.CyanString("Detecting your Linux distribution..."))
distroInfo, err := distro.DetectDistribution()
if err != nil {
return fmt.Errorf("fuck me, couldn't detect your distro: %w", err)
}
fmt.Printf("📦 Found: %s\n", color.GreenString(distroInfo.String()))
fmt.Printf("Found: %s\n", color.GreenString(distroInfo.String()))
if !distroInfo.IsSupported() {
return fmt.Errorf("sorry, %s isn't supported yet - but hey, you're using something exotic! 🦄", distroInfo.ID)
}
// Get mirrors for this distribution family
fmt.Printf("🔧 Loading mirrors for %s family...\n", color.YellowString(distroInfo.Family))
fmt.Printf("Loading mirrors for %s family...\n", color.YellowString(distroInfo.Family))
mirrorList := mirror.NewMirrorList(distroInfo.Family)
@@ -60,8 +60,7 @@ func runFind(cmd *cobra.Command, args []string) error {
return fmt.Errorf("failed to load mirrors: %w", err)
}
fmt.Printf("Testing %d mirrors (timeout: %ds each)...\n",
len(mirrorList.Mirrors), timeout)
fmt.Printf("Testing mirrors (timeout: %ds each)...\n", timeout)
err = mirrorList.TestMirrors(ctx, time.Duration(timeout)*time.Second)
@@ -70,7 +69,7 @@ func runFind(cmd *cobra.Command, args []string) error {
}
// Display results
fmt.Println("\n" + color.GreenString("🎉 Testing complete! Here are your results:"))
fmt.Println("\n" + color.GreenString("Testing complete! Here are your results:"))
fmt.Println()
topMirrors := mirrorList.GetTop(topCount)
@@ -85,11 +84,11 @@ func runFind(cmd *cobra.Command, args []string) error {
}
if verbose {
fmt.Printf("📊 Test Summary: %d/%d mirrors responded successfully\n", successCount, len(allMirrors))
fmt.Printf("Test Summary: %d/%d mirrors responded successfully\n", successCount, len(allMirrors))
fmt.Println()
}
if len(topMirrors) == 0 {
fmt.Println(color.RedString("😱 No working mirrors found. Your internet might be fucked, or all mirrors are down."))
fmt.Println(color.RedString("No working mirrors found. Your internet might be fucked, or all mirrors are down."))
return nil
}
@@ -132,32 +131,29 @@ func runFind(cmd *cobra.Command, args []string) error {
fmt.Println()
best := mirrorList.GetBest()
if best != nil {
fmt.Printf("🏆 Winner: %s\n", color.GreenString(best.URL))
fmt.Printf("This bad boy clocks in at %.1f MB/s with %dms latency\n",
fmt.Printf("Winner: %s\n", color.GreenString(best.URL))
fmt.Printf("This bad boy clocks in at %.1f MB/s with %dms latency\n",
best.Speed, best.Latency.Milliseconds())
}
// Show failed mirrors in verbose mode
// Show failed mirror count in verbose mode (no detailed errors)
if verbose {
failedMirrors := make([]mirror.Mirror, 0)
failedCount := 0
for _, m := range allMirrors {
if m.Error != nil {
failedMirrors = append(failedMirrors, m)
failedCount++
}
}
if len(failedMirrors) > 0 {
if failedCount > 0 {
fmt.Println()
fmt.Printf("Failed mirrors (%d):\n", len(failedMirrors))
for _, m := range failedMirrors {
fmt.Printf(" %s - %s\n", color.RedString(m.URL), m.Error.Error())
}
fmt.Printf("Failed mirrors: %d (errors hidden for cleaner output)\n", failedCount)
}
}
fmt.Println()
fmt.Printf("💡 To apply the fastest mirror, run: %s\n",
color.YellowString("fastestmirror apply"))
fmt.Printf("To apply the fastest mirror, run: %s\n",
color.CyanString("fastestmirror apply"))
return nil
}